QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#421520 | #6532. Trading | HI_SN | WA | 279ms | 3612kb | C++20 | 919b | 2024-05-25 20:33:12 | 2024-05-25 20:33:12 |
Judging History
answer
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
int T, n;
cin >> T;
while(T--){
cin >> n;
unsigned long long ans = 0;
vector<pair<int, unsigned long long> > store(n);
int a;
unsigned long long b;
for(int i = 0; i < n; i++){
cin >> a >> b;
store[i] = make_pair(a, b);
}
sort(store.begin(), store.end());
if(store[0].first == store[n-1].first){
cout << 0 << endl;
continue;
}
int l = 0, r = n - 1;
while(l < r){
unsigned long long temp = store[r].first - store[l].first;
if(store[l].second >= store[r].second){
ans += store[r].second * temp;
store[l].second -= store[r].second;
r--;
}else{
ans += store[l].second * temp;
store[l].second = 0;
store[r].second -= store[l].second;
}
if(!store[l].second)
l++;
}
cout << ans << endl;
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3612kb
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: 279ms
memory: 3568kb
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'