QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#141053 | #6532. Trading | cy1999 | WA | 295ms | 3620kb | C++20 | 900b | 2023-08-17 08:28:58 | 2023-08-17 08:29:00 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
struct node
{
int a,b;
}h[N];
bool cmp(node a,node b)
{
return a.a<b.a;
}
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>h[i].a>>h[i].b;
}
sort(h+1,h+1+n,cmp);
int l=0,r=n+1;
long long suml=0,sumr=0;
while(l<r)
{
r--;
sumr+=h[r].b;
while(l+1<r&&suml<sumr)
{
l++;
suml+=h[l].b;
}
}
if(sumr>suml) sumr=suml;
long long in=0,out=0;
for(int i=n;i>=1;i--)
{
if(sumr>=h[i].b)
{
out+=h[i].b*h[i].a;
sumr-=h[i].b;
}
else
{
out+=h[i].a*sumr;
break;
}
}
for(int i=1;i<=n;i++)
{
if(suml>=h[i].b)
{
in+=h[i].b*h[i].a;
suml-=h[i].b;
}
else
{
in+=h[i].a*suml;
break;
}
}
cout<<out-in<<'\n';
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3620kb
input:
2 4 10 2 30 7 20 4 50 1 2 1 100 1 1000
output:
100 0
result:
ok 2 number(s): "100 0"
Test #2:
score: -100
Wrong Answer
time: 295ms
memory: 3404kb
input:
100000 8 567091 283679 875020 918237 314684 148083 456411 304598 766056 882388 135371 326501 578773 250140 221306 874117 5 126777 129517 846433 679825 649281 330021 427768 362636 390068 692169 5 657677 231119 941936 991342 901241 15133 660372 970476 698958 209343 10 478657 163635 752788 819629 82110...
output:
76564491461 74908747069 136304232834 136228374656 213147025208 150226988944 95875209072 115608118872 18552566090 164358200420 356643455768 148037712679 600904625220 31583389496 0 334984687571 113924584093 75034187258 231479257040 92040757124 5397242676 513848939740 42174787276 0 52266490107 27512936...
result:
wrong answer 1st numbers differ - expected: '974212656325', found: '76564491461'