NYOJ 757 期末考试(优先队列)
2015-07-28 16:48
169 查看
期末考试
时间限制:1000 ms | 内存限制:65535 KB难度:2
描述
马上就要考试了,小T有许多作业要做,而且每个老师都给出来了作业要交的期限,如果在规定的期限内没
交作业就会扣期末成绩的分数,假设完成每门功课需要一天的时间,你能帮助小T扣除的分数最小吗?
输入输入n,表示n门功课(n<2000),接下来n行,每行两个数a,b,分别表示交作业的最后期限,迟交扣除的分数。
(以文件结尾)输出输出扣除的最小分数。样例输入
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
不解释的一道题
ac代码:
#include <stdio.h>
#include <algorithm>
#include <queue>
using namespace std;
struct node
{
int time,value;
}d[2005];
bool cmp(node x,node y)
{
if(x.time==y.time)
return x.value<y.value;
return x.time<y.time;
}
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",&d[i].time,&d[i].value);
sort(d,d+n,cmp);
sum=0;
for(int i=0;i<n;i++)
{
if(s.size()<d[i].time)
s.push(d[i].value);
else
{
int x=s.top();
if(x<d[i].value)//总是用价值最大的把价值最小的替换出来
{
s.pop();
s.push(d[i].value);
sum+=x;
}
else
sum+=d[i].value;
}
}
printf("%d\n",sum);
}
return 0;
}
相关文章推荐
- iOS通知问题之:一眼就看懂的NSNotificationCenter应用
- Number of Digit One
- AHandler机制
- iOS 检测设备旋转状态
- Python 获取根据文件URL 获取文件的基本信息
- 常用第三方库
- js中字符串的拼接的另一种方法
- ShopNC本地生活o2o网站的源代码,没有域名限制
- Xcode界面简介
- 在移动Web页面中使用CSS固定页脚
- Java制作证书的工具keytool用法总结
- 阿里巴巴-业务型产品经理一面
- 理解 pkg-config 工具
- CHKen Tray Clock 2.68珍藏版 51KB免装 任务栏显秒 定时 报时提醒 流量显示
- poj1637 混合图欧拉回路的求解 网络流
- GET和POST的区别
- UI中获取图片的三种方式
- Raspberry vnc 连接
- 阿里巴巴-业务型产品经理一面
- Codeforces313 Equivalent Strings(DFS)