-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2568.cpp
More file actions
38 lines (35 loc) · 925 Bytes
/
Copy path2568.cpp
File metadata and controls
38 lines (35 loc) · 925 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
#include <bits/stdc++.h>
using namespace std;
int n, arr[100010], ans;
pair<int,int> gr[100010];
map<int, int> mp;
vector<int> vec, ansv;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for(int i = 0; i < n; i++){
cin >> gr[i].first >> gr[i].second;
mp[gr[i].second] = gr[i].first;
}
sort(gr, gr+n);
for(int i = 0; i < n; i++){
if(i != 0 && vec[vec.size()-1] < gr[i].second){
vec.push_back(gr[i].second);
}
else if(i != 0){
int ptr = lower_bound(vec.begin(),vec.end(),gr[i].second) - vec.begin();
ans++;
ansv.push_back(vec[ptr]);
vec[ptr] = gr[i].second;
}
else{
vec.push_back(gr[i].second);
}
}
cout << ans << '\n';
// for(int i = 0; i < ansv.size(); i++){
// cout << mp[ansv[i]] << '\n';
// }
}