-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdcp77.cpp
47 lines (42 loc) · 915 Bytes
/
dcp77.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
#include <utility>
#include <algorithm>
using namespace std;
int main() {
int n;
cin >> n;
pair <int,int> pairs[n];
for (int i = 0; i < n; i++) {
cin >> pairs[i].first;
cin >> pairs[i].second;
}
sort(pairs, pairs + n);
bool flag = true, lock = false;
while(flag) {
for (int i = 0; i < n-1; ) {
if (pairs[i+1].first < pairs[i].second) {
if (pairs[i+1].second < pairs[i].second) {
pairs[i+1] = pairs[i];
lock = true;
}
else if(pairs[i+1].second > pairs[i].second) {
pairs[i+1].first = pairs[i].first;
pairs[i].second = pairs[i+1].second;
lock = true;
}
}
i++;
}
if (lock == false)
flag = false;
lock = false;
}
cout << pairs[0].first << " ";
cout << pairs[0].second << endl;
for (int i = 1; i < n; i++) {
if (pairs[i] != pairs[i-1]) {
cout << pairs[i].first << " ";
cout << pairs[i].second << endl;
}
}
}