Descriptionios
Inputide
Outputthis
Sample Inputatom
3 10 3 2 5 3 3
Sample Outputspa
2
Hintorm
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> using namespace std; struct cow{ int w,p,sum; }; int cmp(cow c1,cow c2) { return c1.sum<c2.sum; } cow c[50100]; int main() { int n; //int w[10100],p[10100]; //memset(w,0,sizeof(w)); //memset(p,0,sizeof(p)); while(~scanf("%d",&n)) { for(int i=0;i<n;i++) { scanf("%d%d",&c[i].w,&c[i].p); c[i].sum=c[i].p+c[i].w; } //int sum[10100]; sort(c,c+n,cmp); int ans=-0x3f3f3f3f; int sum=0; for(int i=0;i<n;i++) { //ans+=c[i].p-c[i-1].w; ans=max(ans,sum-c[i].p); sum+=c[i].w; } printf("%d\n",ans); } return 0; }