QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#266765 | #6532. Trading | chitoge# | TL | 0ms | 3528kb | C++20 | 600b | 2023-11-26 17:28:47 | 2023-11-26 17:28:47 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
struct node {
int a, b;
bool operator < (const node &a) const {
return this -> a < a.a;
}
};
void solve() {
int n;
cin >> n;
vector<node> item(n);
for(auto &[x , y] : item) {
cin >> x >> y;
}
sort(item.begin() , item.end());
int l = 0 , r = n - 1;
ll ans = 0;
while(l <= r) {
ans += item[r].a - item[l].a;
--item[r].b;
--item[l].b;
if(item[l].b <= 0) ++l;
if(item[r].b <= 0) --r;
}
cout << ans << '\n';
}
int main(){
int tt;
cin>>tt;
while(tt--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3528kb
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
Time Limit Exceeded
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:
974212656325 422801098045 290923055490 905027520640 1029190811448 678507966352 198954424176 854342493784 14257598794 988991921252 588571689752 736448232231 1193610112068 190497179448 0 931985141715 607845823133 684919543290 764055201744 1066998333316 404829201204 908985930972 518916157132 0 18970544...