Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Make CSP great again
- //You're as beautiful as the day I lost you
- #include <bits/stdc++.h>
- #define TASK "TESTCODE"
- #define Log2(x) 31 - __builtin_clz(x)
- using namespace std;
- const int N = 1e5;
- int n, res, f, g;
- pair<int, char> store[N + 1];
- vector<int> val[2], pos[2];
- void read()
- {
- cin >> n;
- for (int i = 1; i <= n; ++ i)
- {
- cin >> store[i].first >> store[i].second;
- }
- sort(store + 1, store + n + 1);
- val[0] = {0};
- pos[0] = {0};
- }
- void solve()
- {
- for (int i = 1; i <= n; ++ i)
- {
- f += (store[i].second == 'R');
- g += (store[i].second == 'G');
- int t = abs(g - f) & 1;
- int k = upper_bound(val[t].rbegin(), val[t].rend(), g - f) - val[t].rend();
- if (k != -1 && k < val[t].size())
- {
- int j = pos[t][k];
- res = max(res, store[i].first - store[j + 1].first);
- }
- if (val[t].empty() || g - f < val[t].back())
- {
- val[t].push_back(i);
- pos[t].push_back(i);
- }
- }
- cout << res;
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- if (fopen(TASK".INP", "r"))
- {
- freopen(TASK".INP", "r", stdin);
- //freopen(TASK".OUT", "w", stdout);
- }
- int t = 1;
- bool typetest = false;
- if (typetest)
- {
- cin >> t;
- }
- for (int __ = 1; __ <= t; ++ __)
- {
- //cout << "Case " << __ << ": ";
- read();
- solve();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement