95pts 提交RE #19,本地WA
  • 板块P2123 皇后游戏
  • 楼主haooo
  • 当前回复0
  • 已保存回复0
  • 发布时间2020/9/13 16:32
  • 上次更新2023/11/5 13:15:33
查看原帖
95pts 提交RE #19,本地WA
67618
haooo楼主2020/9/13 16:32
#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,本地运行成功。

而且其中有一个答案比标答小。

比较函数有一点问题,但为什么他会标答小?

2020/9/13 16:32
加载中...