LOJ P10004 智力大冲浪 题解
每日一题 day37 打卡
Analysis
经典的带限期和罚款的单位时间任务调度问题
将 val 从大到小排序,优先处理罚款多的,将任务尽量安排在期限之前,并且靠后,如果找不到,则放在最后面
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 }
请各位大佬斧正(反正我不认识斧正是什么意思)