提交时间:2023-08-09 16:49:37

运行 ID: 81602

#include<bits/stdc++.h> using namespace std; #define int long long int n,pre[100005],ans=-1; struct node{ int x,y; }an[100005]; bool cmp(node a,node b){ if(a.x+a.y==b.x+b.y) return a.x>b.x; return a.x+a.y>b.x+b.y; } signed main(){ cin>>n; for(int i=1;i<=n;i++){ cin>>an[i].x>>an[i].y; } sort(an+1,an+n+1,cmp); for(int i=1;i<=n;i++){ pre[i]=pre[i-1]+an[i].x; ans=max(ans,pre[i]+an[i].y); } cout<<ans; return 0; }