Is the question greedy? Okay .. it's really greedy .. I tried a solution a little bit .. it's over... this dislike is to sort all projects by D .. arrange work in this order .. the biggest penalty in the process is .. principle .. I just feel that the gap between the first-to-last-to be-last... no proof...
Program:
#include<stdio.h>#include<iostream>#include<string.h>#include<math.h>#define ll long longusing namespace std;struct node{ ll C,D;}a[100005];ll T,t,n,i,ans,m;bool cmp(node a,node b){ if (a.D!=b.D) return a.D<b.D; return a.C<b.C;}int main(){ freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); scanf("%I64d",&T); for (t=1;t<=T;t++) { scanf("%I64d",&n); for (i=1;i<=n;i++) scanf("%I64d%I64d",&a[i].C,&a[i].D); sort(a+1,a+1+n,cmp); ans=0; m=0; for (i=1;i<=n;i++) { m+=a[i].C; if (m>a[i].D && m-a[i].D>ans) ans=m-a[i].D; } printf("Case %I64d: %I64d\n",t,ans); } return 0;}