CSES - Putka Open 2020 – 2/5 - Results
Submission details
Task:Kortit
Sender:jnalanko
Submission time:2020-09-25 23:13:18 +0300
Language:C++ (C++17)
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED23
#2ACCEPTED77
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2details
#2ACCEPTED0.03 s2details

Code

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;
typedef long long LL;

// Always take smallest that beats the opponent. If does not exist, take smallest in hand.

void solve(){
    LL n; cin >> n;
    set<LL> have;
    for(LL i = 0; i < n/2; i++){
        LL x; cin >> x; have.insert(x);
    }
    set<LL> havenot;
    for(LL x = 1; x <= n; x++){
        if(have.count(x) == 0) havenot.insert(x);
    }

    LL ans = 0;
    for(LL r = 0; r < n/2; r++){
        LL x = *havenot.rbegin(); havenot.erase(x);
        auto yi = lower_bound(have.begin(), have.end(), x);
        if(yi == have.end()) have.erase(have.begin());
        else{
            have.erase(yi);
            ans++;
        }
    }
    cout << ans << "\n";
}

int main(){
    LL t; cin >> t; while(t--) solve();
}

Test details

Test 1

Group: 1, 2

Verdict: ACCEPTED

input
1000
2
1
6
2 4 5
...

correct output
0
2
0
2
1
...

user output
0
2
0
2
1
...
Truncated

Test 2

Group: 2

Verdict: ACCEPTED

input
1000
70
56 23 58 70 2 57 27 61 47 3 42...

correct output
30
15
1
38
29
...

user output
30
15
1
38
29
...
Truncated