#include<bits/stdc++.h>
using namespace std;
#define ll long long
struct node{
ll a,b,c;
}p[200005];
bool cmp(node x,node y){
if(x.a==y.a&&x.b==y.b) return false;
if(x.a+y.b+max(x.b,y.a)==y.a+x.b+max(x.a,y.b)) return x.b>y.a;
return x.a+y.b+max(x.b,y.a)<y.a+x.b+max(x.a,y.b);
}
int main(){
int t;scanf("%d",&t);
while(t--){
int n;scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%lld%lld",&p[i].a,&p[i].b);
p[i].c=0;
}
sort(p+1,p+n+1,cmp);
p[1].c=p[1].a+p[1].b;
ll sum=p[1].a;
ll ans=p[1].c;
for(int i=2;i<=n;i++){//计算最大值
sum+=p[i].a;
p[i].c=p[i].b+max(p[i-1].c,sum);
ans=max(ans,p[i].c);
}
printf("%lld\n",ans);
}
return 0;
}
RE了#19,本地运行成功。
而且其中有一个答案比标答小。
比较函数有一点问题,但为什么他会标答小?