QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#141055 | #6532. Trading | cy1999 | WA | 2ms | 5608kb | C++20 | 983b | 2023-08-17 08:30:21 | 2023-08-17 08:30:25 |
Judging History
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=-1e18;
for(int i=1; i<=n; i++){
long long t=min(sb[i],sb[n]-sb[i]);
int l1=1,r1=i+1;
while(l1<r1){
int mid=(l1+r1+1)>>1;
if(sb[mid]<=t) l1=mid;
else r1=mid-1;
}
long long t1=s[l1-1]+(t-sb[l1-1])*a[p[l1]];
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: 2ms
memory: 5608kb
input:
2 4 10 2 30 7 20 4 50 1 2 1 100 1 1000
output:
80 0
result:
wrong answer 1st numbers differ - expected: '100', found: '80'