QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#141068#6532. Tradingcy1999WA 1ms5452kbC++20975b2023-08-17 08:36:522023-08-17 08:36:55

Judging History

你现在查看的是最新测评结果

  • [2023-08-17 08:36:55]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5452kb
  • [2023-08-17 08:36:52]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;

const int N=100010;

long long a[N],b[N],p[N],n,s[N],sb[N];

bool cmp(const int &x,const int &y){
	return a[x]<a[y];
}

void solve(){
	cin>>n;
	for(int i=1; i<=n; i++) scanf("%lld%lld",a+i,b+i),p[i]=i;
	sort(p+1,p+1+n);
	
	for(int i=1; i<=n; i++) s[i]=s[i-1]+a[p[i]]*b[p[i]],sb[i]=sb[i-1]+b[p[i]];
	
	long long ans=0;
	
	for(int i=1; i<=n; i++){
		long long t=min(sb[i],sb[n]-sb[i]);
		int l1=1,r1=i;
		while(l1<r1){
			int mid=(l1+r1+1)>>1;
			if(sb[mid]<=t) l1=mid;
			else r1=mid-1;
		}
		long long t1=s[l1]+(t-sb[l1])*a[p[l1+1]];
		int l2=i,r2=n;
		while(l2<r2){
			int mid=(l2+r2)>>1;
			if(sb[n]-sb[mid]<=t) r2=mid;
			else l2=mid+1;
		}
		long long t2=s[n]-s[l2]+(t-(sb[n]-sb[l2]))*a[p[l2]];
		ans=max(ans,t2-t1);
	}
	
	cout<<ans<<'\n';
	
}

int main(){
	
	int _;
	cin>>_;
	while(_--) solve();
	
	return 0;
}

/*

2
4
10 2
20 4
30 7
50 1
2
1 100
1 1000

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5452kb

input:

2
4
10 2
30 7
20 4
50 1
2
1 100
1 1000

output:

60
0

result:

wrong answer 1st numbers differ - expected: '100', found: '60'