-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem #200 .cpp
More file actions
42 lines (37 loc) · 891 Bytes
/
Copy pathProblem #200 .cpp
File metadata and controls
42 lines (37 loc) · 891 Bytes
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
#include<bits/stdc++.h>
#define pii pair<int, int>
using namespace std;
vector<int> stabsPoint(vector<pii>&);
int main(){
int t, n, a, b;
cin >> t;
while(t--){
cin >> n;
vector<pii> vec(n);
vector<int> res;
for(int i = 0; i < n; i++){
cin >> a >> b;
vec[i] = {a, b};
}
res = stabsPoint(vec);
for(int i = 0; i < res.size(); i++)
cout << res[i] << " ";
}
return 0;
}
vector<int> stabsPoint(vector<pii> &inter){
vector<int> res;
int max;
sort(inter.begin(), inter.end(), [&](pii &a, pii &b){
return a.second < b.second;
});
max = inter[0].second;
for(int i = 1; i < inter.size(); i++){
if(inter[i].first > max){
res.push_back(max);
max = inter[i].second;
}
}
res.push_back(max);
return res;
}