Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*#pragma GCC optimize("Ofast")
- #pragma GCC optimize("unroll-loops")
- #pragma GCC target("avx,avx2,fma")*/
- // only when really needed
- /* GNU G++17 7.3.0: No long long for faster code
- GNU G++17 9.2.0 (64 bit, msys 2): Long long only for faster code */
- #include <bits/stdc++.h>
- #define for1(i,a,b) for (int i = a; i <= b; i++)
- #define for2(i,a,b) for (int i = a; i >= b; i--)
- #define int long long
- #define sz(a) (int)a.size()
- #define pii pair<int,int>
- /*
- __builtin_popcountll(x) : Number of 1-bit
- __builtin_ctzll(x) : Number of trailing 0
- */
- #define PI 3.1415926535897932384626433832795
- #define INF 1000000000000000000
- #define MOD 1000000007
- #define MOD2 1000000009
- #define EPS 1e-6
- using namespace std;
- int n, ans;
- int a[50005], pre[50005], suf[50005];
- bool f[100005];
- set<int> se;
- signed main() {
- ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
- freopen("cardgame.in", "r", stdin);
- freopen("cardgame.out", "w", stdout);
- cin >> n;
- for1(i,1,n) {
- cin >> a[i];
- f[a[i]] = true;
- }
- for1(i,1,n * 2) if (!f[i]) se.insert(i);
- for1(i,1,n) {
- auto it = se.lower_bound(a[i]);
- pre[i] = pre[i - 1];
- if (it != se.end()) {
- pre[i]++;
- se.erase(it);
- }
- }
- se.clear();
- for1(i,1,n * 2) if (!f[i]) se.insert(i);
- for2(i,n,1) {
- auto it = se.lower_bound(a[i]);
- suf[i] = suf[i + 1];
- if (it != se.begin()) {
- suf[i]++;
- se.erase(prev(it));
- }
- }
- se.clear();
- for1(i,0,n) ans = max(ans, pre[i] + suf[i + 1]);
- cout << ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment