QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#469027 | #7231. Greedy game | propane | WA | 0ms | 3564kb | C++20 | 1.0kb | 2024-07-09 10:48:46 | 2024-07-09 10:48:47 |
Judging History
answer
#include<iostream>
#include<cstring>
#include<vector>
#include<numeric>
#include<queue>
#include<algorithm>
using namespace std;
using LL = long long;
int main(){
#ifdef LOCAL
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int n;
cin >> n;
vector<pair<int, int> > p(n);
for(int i = 0; i < n; i++){
cin >> p[i].first;
}
for(int i = 0; i < n; i++){
int x;
cin >> x;
p[i].second = -x;
}
sort(p.begin(), p.end(), greater<>());
LL ans = 0;
priority_queue<int, vector<int>, greater<int> > q;
for(int i = 0; i < n; i++){
auto [x, y] = p[i];
y = -y;
if (i % 2 == 1){
ans += y;
q.push(y);
}
else{
if (!q.empty() and y > q.top()){
ans += y - q.top();
q.pop();
q.push(y);
}
}
}
cout << ans << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3556kb
input:
5 1 2 3 4 5 2 3 4 5 6
output:
8
result:
ok single line: '8'
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3564kb
input:
10 1 1 1 1 1 1 1 1 1 1 2 3 9 5 6 6 1 2 3 4
output:
30
result:
wrong answer 1st lines differ - expected: '17', found: '30'