标签:
3 3 10 3 5 3 1 3 1 6 3 2 1 3 7 1 3 4 2 6 1 4 7 2 6 4 5 3 4
0 3 5题解:sort先排序,然后判断扣分值,先做分高的;优先队列从小到大,长度代表天;
1 #include<stdio.h> 2 #include<queue> 3 #include<algorithm> 4 #include<string.h> 5 using namespace std; 6 struct Node{ 7 int time,score; 8 }; 9 int cmp(Node a,Node b){ 10 if(a.time!=b.time)return a.time<b.time; 11 else return a.score>b.score; 12 } 13 Node m[2010]; 14 int main(){ 15 int n,day,tot; 16 while(scanf("%d",&n),n){priority_queue<int,vector<int>,greater<int> >work;tot=0; 17 memset(m,0,sizeof(m)); 18 for(int i=0;i<n;++i)scanf("%d%d",&m[i].time,&m[i].score); 19 sort(m,m+n,cmp); 20 for(int i=0;i<n;++i){day=work.size(); 21 if(m[i].time>day)work.push(m[i].score); 22 else{ 23 if(!work.empty()&&m[i].score>work.top())tot+=work.top(),work.pop(),work.push(m[i].score); 24 else tot+=m[i].score; 25 } 26 } 27 printf("%d\n",tot); 28 } 29 return 0; 30 }
标签:
原文地址:http://www.cnblogs.com/handsomecui/p/4684942.html