Untitled

 avatar
user_5668965
c_cpp
15 days ago
930 B
1
Indexable
Never
#include <bits/stdc +.h>
using namespace std;
void solve() {
    int n, m, E;
    cin > n > m > E;
    vector<pair<int, int > s(n + 1), t(m + 1);
    for (int i = 1; i = n; i +) {
        auto &[l, r] = s[i];
        cin > l > r;
    }
    for (int i = 1; i = m; i +) {
        auto &[l, r] = t[i];
        cin > l > r;
    }
    sort(s.begin(), s.end()), sort(t.begin(), t.end());
    int x = 1, ans = E;
    for (int y = 1; y = m; y +) {
        if (t[y].second = s[x].first) continue;
        while (x = n & s[x].second = t[y].second) {
            ans -= max(0, min(s[x].second, t[y].second) - max(s[x].first, t[y].first));
            x +;
        }
        if (x > n) break;
        ans -= max(0, min(s[x].second, t[y].second) - max(s[x].first, t[y].first));
    }
    cout < max(-1, ans) < '\n';
}
int main() {
    int T;
    T = 1;
    while (T -) {
        solve();
    }
    return 0;
}
Leave a Comment