20502022-12-15 22:34:41TomaSajtÁdám és Éva közül legalább az egyikcpp17Accepted 40/4017ms6232 KiB
#include <bits/stdc++.h>
#define speed ios::sync_with_stdio(0);cin.tie(0)
using namespace std;


int main() {
    speed;
    vector<pair<int, int>> ivs;
    int n; cin >> n;
    for (int i = 0; i < 2; i++) {
        cin >> n;
        while (n--) {
            auto& [l, r] = ivs.emplace_back();
            cin >> l >> r;
        }
    }
    sort(ivs.rbegin(), ivs.rend());
    stack<pair<int, int>> s;
    vector<pair<int, int>> res;
    for (auto iv : ivs) s.push(iv);
    while (s.size() >= 2) {
        auto [la, ra] = s.top(); s.pop();
        auto [lb, rb] = s.top(); s.pop();
        if (ra >= lb) s.push({ la, max(ra,rb) });
        else res.push_back({ la,ra }), s.push({ lb,rb });
    }
    if (s.size() == 1) res.push_back(s.top());
    cout << res.size() << '\n';
    for (auto [l, r] : res) cout << l << ' ' << r << '\n';
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/03ms1968 KiB
2Accepted0/02ms2032 KiB
3Accepted2/22ms2032 KiB
4Accepted2/22ms2152 KiB
5Accepted2/22ms2364 KiB
6Accepted2/22ms2700 KiB
7Accepted2/22ms2700 KiB
8Accepted2/22ms2816 KiB
9Accepted2/22ms2984 KiB
10Accepted2/22ms3184 KiB
11Accepted2/22ms3392 KiB
12Accepted2/22ms3604 KiB
13Accepted2/22ms3800 KiB
14Accepted2/22ms4032 KiB
15Accepted2/22ms4232 KiB
16Accepted2/217ms5632 KiB
17Accepted2/216ms5840 KiB
18Accepted2/214ms5772 KiB
19Accepted2/216ms5808 KiB
20Accepted2/217ms6232 KiB
21Accepted2/217ms5848 KiB
22Accepted2/217ms6036 KiB