-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP1803.cpp
More file actions
31 lines (30 loc) · 765 Bytes
/
P1803.cpp
File metadata and controls
31 lines (30 loc) · 765 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
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false); cin.tie(nullptr);
int n;
if(!(cin >> n)) return 0;
struct Item { int a; int b;};
vector<Item> list(n);
for (int i = 0; i < n; i++)
{
cin >> list[i].a >> list[i].b;
}
sort(list.begin(), list.end(), [](const Item &x, const Item &y){
if (x.b != y.b) return x.b < y.b;
return x.a < y.a;
});
int ans = 0;
int last_end = INT_MIN;
for (const auto &it : list)
{
if (it.a >= last_end)
{
ans++;
last_end = it.b;
}
}
cout << ans << endl;
return 0;
}