QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#384550 | #6532. Trading | DDT | WA | 67ms | 3956kb | C++14 | 943b | 2024-04-10 01:21:19 | 2024-04-10 01:21:19 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int INF=0x3f3f3f3f;
#define endl '\n'
#define x first
#define y second
typedef long long ll;
typedef pair<int,int> PII;
PII a[100010];
int n,cnt=0;
void solve()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d%d",&a[i].x,&a[i].y);
cnt+=a[i].y;
}
sort(a+1,a+n+1);
int cnt1,cnt2;
if(cnt&1)cnt1=(cnt-1)/2;
else cnt1=cnt/=2;
cnt2=cnt1;
ll cb=0,xs=0;
for(int i=1;i<=n;i++)
{
cb+=a[i].x*min(a[i].y,cnt1);
cnt1-=min(a[i].y,cnt1);
if(cnt1<=0)break;
}
for(int i=n;i>=1;i--)
{
xs+=a[i].x*min(a[i].y,cnt2);
cnt2-=min(a[i].y,cnt2);
if(cnt2<=0)break;
}
printf("%d\n",max(0ll,xs-cb));
//cout<<xs-cb<<endl;
}
/*
10 2
20 4
25
30 7
50 1
*/
int main()
{
//ios::sync_with_stdio(false);
//ios::sync_with_stdio(0);cin.tie(0),cout.tie(0);
int t;
scanf("%d",&t);
while(t--)
{
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3956kb
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: 67ms
memory: 3892kb
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:
0 0 0 285019488 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -2058779753 1816478952 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 180286859 293335024 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1951861002 0 0 0 0 0 0 0 0 1707572328 0 0 0 0 0 8662...
result:
wrong answer 1st numbers differ - expected: '974212656325', found: '0'