Task: | Kortit |
Sender: | Laakeri |
Submission time: | 2020-09-26 10:27:43 +0300 |
Language: | C++ (C++11) |
Status: | READY |
Result: | 100 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 23 |
#2 | ACCEPTED | 77 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.01 s | 1, 2 | details |
#2 | ACCEPTED | 0.02 s | 2 | details |
Code
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin>>n; set<int> my; set<int> has; for (int i=0;i<n/2;i++){ int x; cin>>x; my.insert(x); has.insert(x); } int p=0; for (int i=n;i>=1;i--){ if (my.count(i)) continue; int x = *has.rbegin(); int y = *has.begin(); if (x>i){ p++; has.erase(x); } else { has.erase(y); } } cout<<p<<endl; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int tcs; cin>>tcs; for (int tc=1;tc<=tcs;tc++){ solve(); } }