QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#469027#7231. Greedy gamepropaneWA 0ms3564kbC++201.0kb2024-07-09 10:48:462024-07-09 10:48:47

Judging History

你现在查看的是最新测评结果

  • [2024-07-09 10:48:47]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3564kb
  • [2024-07-09 10:48:46]
  • 提交

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'