比赛 ry分享赛 评测结果 AAAAWWWWWW
题目名称 服务 最终得分 40
用户昵称 RpUtl 运行时间 9.507 s
代码语言 C++ 内存使用 4.12 MiB
提交时间 2026-03-19 20:52:38
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
const int N=2.5e4+10;
int n;
long long s[N],c[N],ans;
struct node{int a,b;}x[N];
bool cmp(node u,node v){
	return u.b<v.b;
}
long long calc(){
	for(int i=1;i<=n;i++)s[i]=s[i-1]+x[i].a;
	for(int i=1;i<=n;i++)c[i]=max(c[i-1],s[i])+x[i].b;
	return c[n];
}
int main(){
	freopen("service.in","r",stdin);
	freopen("service.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d %d",&x[i].a,&x[i].b);
	}
	ans=1e15;
	sort(x+1,x+1+n,cmp);
	while(1){
		ans=min(ans,calc());
		random_shuffle(x+1,x+1+n);
		if((double)clock()/CLOCKS_PER_SEC>=0.95){
			printf("%lld",ans);
			return 0;
		}
	}
	return 0;
}