QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#421518 | #6530. Programming Contest | HI_SN | WA | 1ms | 3580kb | C++20 | 919b | 2024-05-25 20:32:01 | 2024-05-25 20:32:01 |
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3580kb
input:
4 2003 1 2020 2023 2003 1 2020 2003 2345 0 3456 3000 4 3001 3003 3004 3008 3007
output:
26888834 0 0 0
result:
wrong answer 1st numbers differ - expected: '20', found: '26888834'