HDU 4221 Greedy?(贪心)
题意:
思路:
#include<cstdio> #include<iostream> #include<cstring> #include<cmath> #include<stdlib.h> #include<vector> #include<queue> #include<stack> #include<algorithm> using namespace std; struct Work { __int64 c,d; }; Work work[100000+10]; int cmp(Work a,Work b) { if(a.d==b.d) { return a.c<b.c; } return a.d<b.d; } int main() { __int64 time ,ans; int cas=1; int t,n; int i,j,k; scanf("%d",&t); while(t--) { ans=0;time=0; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%I64d%I64d",&work[i].c,&work[i].d); } sort(work,work+n,cmp); for(i=0;i<n;i++) { time+=work[i].c; if(time>work[i].d&&ans<time-work[i].d) { ans=time-work[i].d; } } printf("Case %d: %I64d\n",cas++,ans); } return 0; }