QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#266767 | #6532. Trading | chitoge# | TL | 1ms | 3472kb | C++20 | 651b | 2023-11-26 17:29:20 | 2023-11-26 17:29:21 |
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(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
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: 1ms
memory: 3472kb
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...