Mike4235

USACO_DEC2015_PLATINUM HighCardLowCard

Jun 25th, 2021
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.61 KB | None | 0 0
  1. /*#pragma GCC optimize("Ofast")
  2. #pragma GCC optimize("unroll-loops")
  3. #pragma GCC target("avx,avx2,fma")*/
  4. // only when really needed
  5.  
  6. /* GNU G++17 7.3.0: No long long for faster code
  7.    GNU G++17 9.2.0 (64 bit, msys 2): Long long only for faster code */
  8.  
  9. #include <bits/stdc++.h>
  10.  
  11. #define for1(i,a,b) for (int i = a; i <= b; i++)
  12. #define for2(i,a,b) for (int i = a; i >= b; i--)
  13. #define int long long
  14.  
  15. #define sz(a) (int)a.size()
  16. #define pii pair<int,int>
  17.  
  18. /*
  19. __builtin_popcountll(x) : Number of 1-bit
  20. __builtin_ctzll(x) : Number of trailing 0
  21. */
  22.  
  23. #define PI 3.1415926535897932384626433832795
  24. #define INF 1000000000000000000
  25. #define MOD 1000000007
  26. #define MOD2 1000000009
  27. #define EPS 1e-6
  28.  
  29. using namespace std;
  30.  
  31. int n, ans;
  32. int a[50005], pre[50005], suf[50005];
  33. bool f[100005];
  34. set<int> se;
  35.  
  36. signed main() {
  37.    
  38.     ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  39.  
  40.     freopen("cardgame.in", "r", stdin);
  41.     freopen("cardgame.out", "w", stdout);
  42.  
  43.     cin >> n;
  44.     for1(i,1,n) {
  45.         cin >> a[i];
  46.         f[a[i]] = true;
  47.     }
  48.  
  49.     for1(i,1,n * 2) if (!f[i]) se.insert(i);
  50.     for1(i,1,n) {
  51.         auto it = se.lower_bound(a[i]);
  52.         pre[i] = pre[i - 1];
  53.         if (it != se.end()) {
  54.             pre[i]++;
  55.             se.erase(it);
  56.         }
  57.     }
  58.     se.clear();
  59.  
  60.     for1(i,1,n * 2) if (!f[i]) se.insert(i);
  61.     for2(i,n,1) {
  62.         auto it = se.lower_bound(a[i]);
  63.         suf[i] = suf[i + 1];
  64.         if (it != se.begin()) {
  65.             suf[i]++;
  66.             se.erase(prev(it));
  67.         }
  68.     }
  69.     se.clear();
  70.  
  71.     for1(i,0,n) ans = max(ans, pre[i] + suf[i + 1]);
  72.     cout << ans;
  73.    
  74. }
Advertisement
Add Comment
Please, Sign In to add comment