hdu 4221 Greedy?

题目链接:

点击打开链接


贪心水题, “he wants the maximum penalty of all the tasks to be as small as possible. ”指的是所有任务中最大的罚时数。


代码:

#include 
#include 
#include 
using namespace std;
struct node{
    int a,b;
};

node N[100005];
bool cmp(node x,node y){
    return x.b>T;
    while(T--){
          cin>>n;
          for(int i=1;i<=n;i++){
                    scanf("%d%d",&N[i].a,&N[i].b);
          }
          long long res=0;
          long long cur=0;
          sort(N+1,N+n+1,cmp);
          for(int i=1;i<=n;i++){
                cur+=N[i].a;
                if(cur>=N[i].b)
                    res=max(res,cur-N[i].b);
          }
          printf("Case %d: %I64d\n",flag++,res);
    }
    return 0;
}


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