QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#141138 | #6532. Trading | cy1999 | WA | 1ms | 5792kb | C++20 | 981b | 2023-08-17 08:56:56 | 2023-08-17 08:56:58 |
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=0;
for(int i=1; i<=n; i++){
long long t=min(sb[i],sb[n]-sb[i]);
int l1=0,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
3
1 200
32 20
5 1
*/
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5792kb
input:
2 4 10 2 30 7 20 4 50 1 2 1 100 1 1000
output:
50 0
result:
wrong answer 1st numbers differ - expected: '100', found: '50'