63212023-11-16 22:11:01kukkermanÁdám és Éva együttcpp14Accepted 50/5090ms10428 KiB
#include <iostream>
#include <vector>
#include <algorithm>

using Intervallumok = std::vector<std::pair<int, int>>;

void beolvas(std::istream &in, Intervallumok &adam, Intervallumok &eva) {
    int utolso_idopont;
    in >> utolso_idopont;

    int adam_idopontok_szama;
    in >> adam_idopontok_szama;
    adam.resize(adam_idopontok_szama);
    for (int i = 0; i < adam_idopontok_szama; i++) {
        in >> adam[i].first >> adam[i].second;
    }

    int eva_idopontok_szama;
    in >> eva_idopontok_szama;
    eva.resize(eva_idopontok_szama);
    for (int i = 0; i < eva_idopontok_szama; i++) {
        in >> eva[i].first >> eva[i].second;
    }
}

void feldolgoz(const Intervallumok &adam, const Intervallumok &eva) {
    Intervallumok kozos;

    auto a = adam.cbegin();
    auto e = eva.cbegin();
    while (a != adam.cend() && e != eva.cend()) {
        const auto k = std::max(a->first,  e->first);
        const auto v = std::min(a->second, e->second);

        if (k < v) {
            kozos.emplace_back(k, v);
        }

        if (a->second == e->second ?
            a->first   < e->first  :
            a->second  < e->second) {

            ++a;

        } else {
            ++e;
        }
    }

    std::cout << kozos.size() << std::endl;
    for (const auto &k : kozos) {
        std::cout << k.first << ' ' << k.second << std::endl;
    }
}

int main() {
    Intervallumok adam, eva;
    beolvas(std::cin, adam, eva);

    feldolgoz(adam, eva);

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1816 KiB
2Accepted0/03ms1984 KiB
3Accepted2/23ms2220 KiB
4Accepted2/23ms2400 KiB
5Accepted2/23ms2528 KiB
6Accepted2/23ms2684 KiB
7Accepted2/23ms2696 KiB
8Accepted2/23ms2732 KiB
9Accepted2/23ms2948 KiB
10Accepted2/23ms3160 KiB
11Accepted2/23ms3380 KiB
12Accepted2/23ms3628 KiB
13Accepted2/23ms3836 KiB
14Accepted2/23ms3924 KiB
15Accepted2/23ms3908 KiB
16Accepted2/279ms6012 KiB
17Accepted3/357ms6956 KiB
18Accepted3/372ms7712 KiB
19Accepted4/454ms8136 KiB
20Accepted4/490ms9044 KiB
21Accepted4/457ms9864 KiB
22Accepted4/457ms10428 KiB