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
记得以前做过类似的 就直接敲了
#include <stdio.h>
#include <algorithm>
#include <queue>
using namespace std;
struct node
{int day,cost;
}c[2005];
bool cmp(node x,node y)
{if(x.day<y.day) return true;if(x.day==y.day&&st&st) return true;return false;
}
int main()
{int n,sum;priority_queue<int,vector<int>,greater<int> >s;while(scanf("%d",&n)!=EOF){while(!s.empty())s.pop();for(int i=0;i<n;i++)scanf("%d %d",&c[i].day,&c[i].cost);sort(c,c+n,cmp);sum=0;for(int i=0;i<n;i++){if(s.size()<c[i].day)//s.size()可以理解为天数。如果当前天数小于最后完成的天数,证明还是有天数空间的,直接入队列s.push(c[i].cost);else//如果当前天数大于最后完成的天数,必须要扣除分数了,为了使得扣除的分数最小,比较s.top()和当前的c[i].cost,舍弃扣除的最小的{int xp();if(x<c[i].cost)s.pop(),s.push(c[i].cost),sum+=x;elsesum+=c[i].cost;}}printf("%dn",sum);}return 0;
}
本文发布于:2024-01-30 16:02:34,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170660175821189.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |