QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#619847#8034. Ban or Pick, What's the Trickmhw#WA 0ms3840kbC++201.9kb2024-10-07 15:38:392024-10-07 15:38:41

Judging History

This is the latest submission verdict.

  • [2024-10-07 15:38:41]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3840kb
  • [2024-10-07 15:38:39]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
const i64 P = 998244353;
void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n), b(n), c, d;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    for (int i = 0; i < 2 * n; i++) {
        int f = i % 2;
        if (f == 0) {
            if (b.size() == 0) {
                c.push_back(a.back());
                // cout << a.back() << '\n';
                a.pop_back();
            } else if (c.size() >= k || a.size() == 0) {
                b.pop_back();
            } else {
                if (a.back() == b.back()) {
                    b.pop_back();
                } else if (a.back() > b.back()) {
                    c.push_back(a.back());
                    // cout << a.back() << '\n';
                    a.pop_back();
                } else {
                    b.pop_back();
                }
            }
        } else {
            if (a.size() == 0) {
                d.push_back(b.back());
                // cout << b.back() << '\n';
                b.pop_back();
            } else if (d.size() >= k || b.size() == 0) {
                a.pop_back();
            } else {
                if (a.back() == b.back()) {
                    a.pop_back();
                } else if (a.back() < b.back()) {
                    d.push_back(b.back());
                    // cout << b.back() << '\n';
                    b.pop_back();
                } else {
                    a.pop_back();
                }
            }
        }
    }
    i64 ans = 0;
    for (auto it : c) ans += it;
    for (auto it : d) ans -= it;
    cout << ans << '\n';
}
int main() {
    ios::sync_with_stdio(0); cin.tie(0), cout.tie(0);
    int t = 1;
    // cin >> t;
    while (t--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3612kb

input:

2 1
3 6
2 4

output:

2

result:

ok single line: '2'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3488kb

input:

4 1
1 3 5 7
2 4 6 8

output:

0

result:

ok single line: '0'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3544kb

input:

4 2
4 6 7 9
2 5 8 10

output:

3

result:

ok single line: '3'

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 3840kb

input:

10 5
42 13 60 42 100 82 22 98 14 55
100 41 89 24 65 38 69 26 37 16

output:

39

result:

wrong answer 1st lines differ - expected: '41', found: '39'