每日一題 day37 打卡node
經典的帶限期和罰款的單位時間任務調度問題ios
將 val 從大到小排序,優先處理罰款多的,將任務儘可能安排在期限以前,而且靠後,若是找不到,則放在最後面git
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #define int long long 6 #define maxn 500+10 7 #define rep(i,s,e) for(register int i=s;i<=e;++i) 8 #define dwn(i,s,e) for(register int i=s;i>=e;--i) 9 using namespace std; 10 inline int read() 11 { 12 int x=0; 13 bool f=1; 14 char c=getchar(); 15 for(; !isdigit(c); c=getchar()) if(c=='-') f=0; 16 for(; isdigit(c); c=getchar()) x=(x<<3)+(x<<1)+c-'0'; 17 if(f) return x; 18 return 0-x; 19 } 20 inline void write(int x) 21 { 22 if(x<0){putchar('-');x=-x;} 23 if(x>9)write(x/10); 24 putchar(x%10+'0'); 25 } 26 int m,n,sum; 27 struct node 28 { 29 int tim,_val; 30 }x[maxn]; 31 int book[maxn]; 32 bool cmp(node x,node y) 33 { 34 return x._val>y._val; 35 } 36 signed main() 37 { 38 m=read();n=read(); 39 rep(i,1,n) x[i].tim=read(); 40 rep(i,1,n) x[i]._val=read(); 41 sort(x+1,x+n+1,cmp); 42 rep(i,1,n) 43 { 44 int flag=0; 45 dwn(j,x[i].tim,1) 46 if(book[j]==0) 47 { 48 book[j]=1; 49 flag=1; 50 break; 51 } 52 if(flag==0) 53 { 54 dwn(j,n,1) 55 if(book[j]==0) 56 { 57 book[j]=1; 58 break; 59 } 60 sum+=x[i]._val; 61 } 62 } 63 write(m-sum); 64 return 0; 65 }
請各位大佬斧正(反正我不認識斧正是什麼意思)spa