46002023-03-30 10:57:25ZsBalazsÁdám és Éva együttcpp17Accepted 50/5098ms7648 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
  int m;
  cin >> m;
  
  // idopont * -1, miTortent, kicsoda
  // start => 0
  // end => 1
  priority_queue<pair<int, pair<int, int>>> sor;
  
  int n;
  cin >> n;
  
  for (int i = 0; n > i; i++) {
    int a, b;
    cin >> a >> b;
    
    sor.push({a*-1, {0, 0}});
    sor.push({b*-1, {1, 0}});
  }
  
  cin >> n;
  
  for (int i = 0; n > i; i++) {
    int a, b;
    cin >> a >> b;
    
    sor.push({a*-1, {0, 1}});
    sor.push({b*-1, {1, 1}});
  }
  
  bool adam = false;
  bool eve = false;
  int honnantol = -1;
  
  vector<pair<int, int>> ans;
  
  while (!sor.empty()) {
    auto top = sor.top();
    sor.pop();
    
    int mikor = top.first * -1;
    int tipus = top.second.first;
    int kicsoda = top.second.second;
    
    if (tipus == 0) {
      // belepes
      if (kicsoda == 0) adam = true;
      else eve = true;
      
      if (adam && eve) {
        honnantol = mikor;
      }
    } else {
      // Ez egy kilepes
      if (adam && eve) {
        // Eddig ment
        ans.push_back({honnantol, mikor});
      }
      
      if (kicsoda == 0) adam = false;
      else eve = false;
    }
  }
  
  if (adam && eve) {
    ans.push_back({honnantol, m});
  }
  
  cout << ans.size() << endl;
  
  for (auto par : ans) {
    cout << par.first << " " << par.second << endl;
  }
  
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1812 KiB
2Accepted0/03ms2008 KiB
3Accepted2/23ms2216 KiB
4Accepted2/22ms2432 KiB
5Accepted2/22ms2640 KiB
6Accepted2/22ms2852 KiB
7Accepted2/23ms3096 KiB
8Accepted2/23ms3308 KiB
9Accepted2/22ms3392 KiB
10Accepted2/23ms3480 KiB
11Accepted2/23ms3488 KiB
12Accepted2/23ms3612 KiB
13Accepted2/23ms3608 KiB
14Accepted2/23ms3704 KiB
15Accepted2/22ms3784 KiB
16Accepted2/298ms7100 KiB
17Accepted3/393ms7316 KiB
18Accepted3/364ms7524 KiB
19Accepted4/467ms7504 KiB
20Accepted4/472ms7504 KiB
21Accepted4/470ms7496 KiB
22Accepted4/468ms7648 KiB