153932025-02-19 11:22:34mateÁdám és Éva együttcpp17Time limit exceeded 26/50501ms25040 KiB
#include <bits/stdc++.h>
#include <cstdint>
#include <vector>
using namespace std;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
    vector<bool> v(n+1,1);
    vector<bool> w(n+1,1);
    int a ,e; cin >> a;
    int b,c;
    int k = INT_MAX,f = 1;
    while(a--){
        cin >> b >> c;
        k = min(k,b);
        f = max(f,c);
        for(int i = b; i < c; i++){
            w[i] = 0;
        }
    }
    cin >> e;
    while(e--){
        cin >> b >> c;
        k = min(k,b);
        f = max(f,c);
        for(int i = b; i < c; i++){
            if(w[i] == 0)
            v[i] = 0;
        }
    }
    int cnt = 0;
    bool igaz = 0;
    int kezd = 0;
    vector <pair<int,int>> ans;
    for(int i = k; i <= f; i++){
        if(v[i] == 0 && !igaz){
            cnt++;
            igaz = 1;
            kezd = i;
        }
        if(v[i] > 0 && igaz){
            ans.push_back({kezd,i});
            igaz = 0;
        }
    }
    cout << cnt << '\n';
    for(auto x : ans){
        cout << x.first << ' ' << x.second << '\n';
    }
}
SubtaskSumTestVerdictTimeMemory
base26/50
1Accepted0/01ms508 KiB
2Accepted0/02ms316 KiB
3Accepted2/21ms316 KiB
4Accepted2/21ms316 KiB
5Accepted2/21ms316 KiB
6Accepted2/21ms316 KiB
7Accepted2/21ms316 KiB
8Accepted2/21ms316 KiB
9Accepted2/21ms316 KiB
10Accepted2/21ms316 KiB
11Accepted2/21ms316 KiB
12Accepted2/21ms316 KiB
13Accepted2/22ms508 KiB
14Accepted2/21ms508 KiB
15Accepted2/24ms540 KiB
16Time limit exceeded0/2501ms24896 KiB
17Time limit exceeded0/3501ms24896 KiB
18Time limit exceeded0/3501ms22520 KiB
19Time limit exceeded0/4500ms23680 KiB
20Time limit exceeded0/4483ms24804 KiB
21Time limit exceeded0/4500ms25000 KiB
22Time limit exceeded0/4501ms25040 KiB