期末考试
时间限制:
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
-
#include<cstdio> #include<iostream> #include<algorithm>//要用sort排序 #include<queue>//队头文件 using namespace std; priority_queue<int,vector<int>,greater<int> >q;//从小到大排列队列定义,记死!!!!!!!!!!!!! struct nobe//定义结构体变量nobe { int day;//提交日期 int cost;//扣的分 } c[2000];//定义结构体数组 bool cmp(nobe a,nobe b)//bool函数从小到大排天数,若天数相同,按扣的分从小到大排列 { if(a.day<b.day) return true; else if(a.day==b.day&&a.cost<b.cost) return true; return false; } int main() { int n,i,sum; while(~scanf("%d",&n)) { while(!q.empty())//队列清空 { q.pop(); } for(i=0;i<n;i++) { scanf("%d %d",&c[i].day,&c[i].cost);//输入数组 } sort(c,c+n,cmp);//按天数从小到大排 sum=0; for(i=0;i<n;i++) { if(q.size()<c[i].day)//q.size()即表示队列的长度也表示天数;如果天数小于期限的话就缓缓在作,既存入队列 q.push(c[i].cost); else { int x=q.top();//我觉得就有一种可能天数等于当天期限,就只能比较扣分大小,输出扣分小的; if(x<c[i].cost) { q.pop(); q.push(c[i].cost); sum=sum+x; } else sum=sum+c[i].cost; } } printf("%d\n",sum); } return 0; }
-
输入n,表示n门功课(n<2000),接下来n行,每行两个数a,b,分别表示交作业的最后期限,迟交扣除的分数。