Advertisement
tien_noob

Stores

Feb 25th, 2022
913
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.48 KB | None | 0 0
  1. //Make CSP great again
  2. //You're as beautiful as the day I lost you
  3. #include <bits/stdc++.h>
  4. #define TASK "TESTCODE"
  5. #define Log2(x) 31 - __builtin_clz(x)
  6. using namespace std;
  7. const int N = 1e5;
  8. int n, res, f, g;
  9. pair<int, char> store[N + 1];
  10. vector<int> val[2], pos[2];
  11. void read()
  12. {
  13.     cin >> n;
  14.     for (int i = 1; i <= n; ++ i)
  15.     {
  16.         cin >> store[i].first >> store[i].second;
  17.     }
  18.     sort(store + 1, store + n + 1);
  19.     val[0] = {0};
  20.     pos[0] = {0};
  21. }
  22. void solve()
  23. {
  24.     for (int i = 1; i <= n; ++ i)
  25.     {
  26.         f += (store[i].second == 'R');
  27.         g += (store[i].second == 'G');
  28.         int t = abs(g - f) & 1;
  29.         int k = upper_bound(val[t].rbegin(), val[t].rend(), g - f) - val[t].rend();
  30.         if (k != -1 && k < val[t].size())
  31.         {
  32.             int j = pos[t][k];
  33.             res = max(res, store[i].first - store[j + 1].first);
  34.         }
  35.         if (val[t].empty() || g - f < val[t].back())
  36.         {
  37.             val[t].push_back(i);
  38.             pos[t].push_back(i);
  39.         }
  40.     }
  41.     cout << res;
  42. }
  43. int main()
  44. {
  45.     ios_base::sync_with_stdio(false);
  46.     cin.tie(nullptr);
  47.     if (fopen(TASK".INP", "r"))
  48.     {
  49.         freopen(TASK".INP", "r", stdin);
  50.         //freopen(TASK".OUT", "w", stdout);
  51.     }
  52.     int t = 1;
  53.     bool typetest = false;
  54.     if (typetest)
  55.     {
  56.         cin >> t;
  57.     }
  58.     for (int __ = 1; __ <= t; ++ __)
  59.     {
  60.         //cout << "Case " << __ << ": ";
  61.         read();
  62.         solve();
  63.     }
  64. }
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement