Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Слава Україні, Героям слава
- #include <bits/stdc++.h>
- using namespace std;
- using ll = long long;
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- freopen("in.txt", "r", stdin);
- freopen("out.txt", "w", stdout);
- int n;
- cin >> n;
- set<pair<ll, ll>> s;
- for(int i = 0; i < n; i += 2) {
- ll a, b;
- cin >> a >> b;
- s.insert({a, a + b - 1});
- }
- int q;
- cin >> q;
- vector<set<pair<pair<ll, ll>, pair<ll, ll>>>> v(q);
- for(int i = 0; i < q; i++) {
- int m;
- cin >> m;
- for(int j = 0; j < m; j++) {
- ll a, b, c;
- cin >> b >> a >> c;
- v[i].insert({{a, a + c - 1}, {b, b + c - 1}});
- }
- }
- for(int i = 0; i < q; i++) {
- set<pair<ll, ll>> tmp;
- while(!s.empty()) {
- auto x = *s.begin();
- s.erase(s.begin());
- auto itr = v[i].lower_bound({{x.first + 1, 0}, {0, 0}});
- if(itr == v[i].begin()) {
- tmp.insert(x);
- continue;
- }
- itr--;
- if(x.second < itr->first.first or x.first > itr->first.second) {
- tmp.insert(x);
- continue;
- }
- if(x.second <= itr->first.second) {
- ll diff = itr->second.first - itr->first.first;
- x.first += diff;
- x.second += diff;
- tmp.insert(x);
- continue;
- }
- ll diff = itr->second.first - itr->first.first;
- tmp.insert({x.first + diff, itr->first.second + diff});
- s.insert({itr->first.second + 1, x.second});
- }
- s = tmp;
- }
- cout << s.begin()->first << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement