hdu4221 Greedy

Greedy?

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2866    Accepted Submission(s): 945


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.
 

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
 

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
// if a work is finished after Di, says Ti, he will get a penalty Ti - Di. 
//意思是 如果一个工作在Di天之后,即Ti天完成,那么惩罚是Ti-Di 
#include
#include
#include
#include
using namespace std;
const int MAXN=100010;
struct Node
{
    int c,d;
}node[MAXN];

bool cmp(Node a,Node b)
{
    return a.dans)//题意是要记录最大的一次惩罚,而不是把所有惩罚相加 
			ans=sum-node[i].d;
        }
        printf("Case %d: %I64d\n",iCase,ans);
    }
    return 0;
}

你可能感兴趣的:(贪心)