QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#221105 | #6532. Trading | haze | WA | 38ms | 3808kb | C++20 | 1.6kb | 2023-10-21 09:15:44 | 2023-10-21 09:15:45 |
Judging History
answer
#include<bits/stdc++.h>
#define irep(i,l,r) for(int (i) = (l); (i) <= (r); ++(i))
#define drep(i,r,l) for(int (i) = (r); (i) >= (l); --(i))
#define ceil(pp,qq) (((pp)>0)^((qq)>0)?-abs(pp)/abs(qq):(pp)%(qq)?(pp)/(qq)+1:(pp)/(qq))
#define floor(pp,qq) (((pp)>0)^((qq)>0)?-ceil(abs(pp),abs(qq)):(pp)/(qq))
#define ll long long
#define LL __int128
using namespace std;
inline ll read(){
char ch = getchar();
ll s = 0; bool w = 0;
while(!isdigit(ch)){if(ch == '-')w = 1;ch = getchar();}
while(isdigit(ch))s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
return w ? - s : s;
}
inline char rc(){
char ch = getchar();
while(1){
if(ch >= 'A' && ch <= 'Z')return ch;
if(ch >= 'a' && ch <= 'z')return ch;
ch = getchar();
}
}
template<class T1, class T2>
T1 min(T1 AA, T2 BB){return AA > BB ? BB : AA;}
template<class T1, class T2>
T1 max(T1 AA, T2 BB){return AA < BB ? BB : AA;}
const int itinf = 1e9;
const ll llinf = 4e18;
const int mod = 1000000007;
const int N = 500009;
void solve(){
int n = read();
vector<array<ll, 2>>a(n);
irep(i, 0, n - 1){
a[i] = {read(), read()};
}
sort(a.begin(), a.end());
auto p = a.begin(), q = a.end();
-- q;
ll ans = 0;
while(p < q){
auto [in, c1] = *p;
auto [out, c2] = *q;
ans += 1ll * (out - in) * min(c1, c2);
if(c1 == c2)++ p, -- q;
else if(c1 > c2)c1 -= c2, *p = {in, c1}, -- q;
else *q = {out, c2}, ++ p;
}
printf("%lld\n", ans);
}
int main(){
int T = read();
while(T --){
solve();
}
return 0;
}
/*
50 30 30 30 30 30 30 30
10 10 20 20 20 20
40 20 10 10 10 10
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3772kb
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: 38ms
memory: 3808kb
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:
1281007100160 479759689322 390430341174 1116204445744 1491423573098 791234908004 198954424176 1112399243099 14257598794 1560061838548 643222056804 957665608000 1554922394333 237175705692 0 1297542286789 714985779026 1007082228830 890429329974 1668885341118 819214004462 1258487361357 547471672972 0 1...
result:
wrong answer 1st numbers differ - expected: '974212656325', found: '1281007100160'