题目描述

有2N张牌,它们的点数分别为1到2N。Alice拿了其中的N张,Bob拿了剩下的N张. Alice和Bob会进行N轮游戏,在每轮游戏中,Alice 和Bob 各出一张牌。出了的牌不能收回。每轮谁的牌点数大谁就赢; 已知Bob 每一轮会出什么牌,试求Alice 最多能赢多少轮。

输入

第一行是一个整数N,

接下来N行,每行一个整数,表示Bob这轮会出什么。
2<=N <= 100000,

输出

Alice最多能赢几轮

样例输入

4
1 3 4 8

样例输出

3

提示

Bob手里的牌是1 3 4 8
Alice手里的牌为2 5 6 7
显然Alice 可以选择用

2 v 1
5 v 3
6 v 4
这样就可以赢3轮 

题解

#include<bits/stdc++.h>

using namespace std;
using ll = long long;
#define endl '\n'
#define REP(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define PER(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)

template<typename T=int>
inline T read() {
    T x;
    cin >> x;
    return x;
}

const int maxn = 2e5 + 500;
int book[maxn], n;
vector<int> a, b;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> n;
    for (int i = 0; i < n; i++) {
        int t = read();
        book[t] = 1;
    }
    for (int i = 1; i <= 2 * n; i++) {
        if (book[i] == 1)
            b.push_back(i);
        else
            a.push_back(i);
    }
    int p = 0, win = 0;
    for (int e: a) {
        int q = upper_bound(b.begin(), b.end(), e) - b.begin();
        if (q > p) {
            ++win;
            p++;
        }
    }
    cout << win << endl;
    return 0;
}