hdu4221(贪心)
来源:互联网 发布:淘宝话费券 编辑:程序博客网 时间:2024/06/04 19:27
Greedy?
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2583 Accepted Submission(s): 870
Problem Description
iSea is going to be CRAZY! Recently, he was assigned a lot of works to do, so many that you can't imagine. Each task costs Ci time as least, and the worst news is, he must do this work no later than time Di!
OMG, how could it be conceivable! After simple estimation, he discovers a fact that if a work is finished after Di, says Ti, he will get a penalty Ti - Di. Though it may be impossible for him to finish every task before its deadline, he wants the maximum penalty of all the tasks to be as small as possible. He can finish those tasks at any order, and once a task begins, it can't be interrupted. All tasks should begin at integral times, and time begins from 0.
OMG, how could it be conceivable! After simple estimation, he discovers a fact that if a work is finished after Di, says Ti, he will get a penalty Ti - Di. Though it may be impossible for him to finish every task before its deadline, he wants the maximum penalty of all the tasks to be as small as possible. He can finish those tasks at any order, and once a task begins, it can't be interrupted. All tasks should begin at integral times, and time begins from 0.
Input
The first line contains a single integer T, indicating the number of test cases.
Each test case includes an integer N. Then N lines following, each line contains two integers Ci and Di.
Technical Specification
1. 1 <= T <= 100
2. 1 <= N <= 100 000
3. 1 <= Ci, Di <= 1 000 000 000
Each test case includes an integer N. Then N lines following, each line contains two integers Ci and Di.
Technical Specification
1. 1 <= T <= 100
2. 1 <= N <= 100 000
3. 1 <= Ci, Di <= 1 000 000 000
Output
For each test case, output the case number first, then the smallest maximum penalty.
Sample Input
223 42 243 62 74 53 9
Sample Output
Case 1: 1Case 2: 3
Author
iSea@WHU
Source
首届华中区程序设计邀请赛暨第十届武汉大学程序设计大赛
Recommend
lcy | We have carefully selected several similar problems for you: 4224 4223 4219 4218 4217
#include<cstdio>#include<iostream>#include<string.h>#include<algorithm>using namespace std;typedef long long ll;struct node{int ci;int di;}task[100010];bool cmp(node a,node b){return a.di<b.di;}int main(){int t;int n;int cas=1;scanf("%d",&t);while(t--){scanf("%d",&n);for(int i=0;i<n;i++){scanf("%d%d",&task[i].ci,&task[i].di);}ll res;ll ans;res=0;ans=0;sort(task,task+n,cmp);for(int i=0;i<n;i++){res+=task[i].ci;if(ans<res-task[i].di)ans=res-task[i].di;}cout<<"Case "<<cas<<": ";printf("%lld\n",ans);cas++;}return 0;}
阅读全文
0 0
- hdu4221(贪心)
- hdu4221(贪心)
- HDU4221(Greedy?)贪心
- hdu4221 Greedy?(贪心)
- hdu4221
- hdu4221
- hdu4221-Greedy?
- hdu4221 Greedy?
- hdu4221 Greedy
- hdu4221 Greedy?
- 贪心!
- 贪心~
- 贪心
- 贪心
- 贪心
- 贪心
- 贪心
- 贪心
- 【概率论】作业一
- 文章标题
- HDU 3308 LCIS(线段树+区间合并+最长递增连续子串)
- LeetCode21. Merge Two Sorted Lists
- 机器学习心得之Andrew Ng(2)
- hdu4221(贪心)
- 《架构即服务--企业数字化运营架构设计与演进》缩略语
- 【概率论】作业二
- 在一个多core 服务器上,怎么限制RHEL识别到的cpu的数量?
- python.matplotlib/random.choice学习范例-随机生成点图
- 信号报告
- bzoj 4364: [IOI2014]wall砖墙
- 【洛谷】P1629 邮递员送信
- 剑指offer-(1-5)