期末考试

时间限制: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
错把
<span style="color:#ff0000;background-color: rgb(102, 255, 153);">int cmp(stu a,stu b){
	if(a.x==b.x)
	return a.y<b.y;
	return a.x<b.x;
}</span>
<span style="color:#ff0000;background-color: rgb(102, 255, 153);">写成</span><pre name="code" class="cpp" style="font-size: 14px; line-height: 21px;"><span style="color:#ff0000;background-color: rgb(102, 255, 153);">int cmp(stu a,stu b){
	if(a.x==b.x)
	return a.y>b.y;
	return a.x>b.x;
}</span>
 
   
 
   
#include<stdio.h>
#include<queue>
#include<algorithm>
using namespace std;
struct stu{
	int x,y;
}aa[1000];
int cmp(stu a,stu b){
	if(a.x==b.x)
	return a.y<b.y;
	return a.x<b.x;
}
int main()
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		int i;
	//	while()
	    priority_queue<int ,vector<int>,greater<int> >s;
		for(i=0;i<n;i++)
		scanf("%d%d",&aa[i].x,&aa[i].y);
		int sum=0;
		sort(aa,aa+n,cmp);
		for(i=0;i<n;i++)
		{
           if(s.size()<aa[i].x)
           s.push(aa[i].y);
           else{
           	if(s.top()<aa[i].y)
           	{
           		sum+=s.top();
           		s.pop();
           		s.push(aa[i].y);
           	}
           	else sum+=aa[i].y;
           }  
		}
		printf("%d\n",sum);
	}
			return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值