-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path9576.cpp
More file actions
52 lines (42 loc) · 972 Bytes
/
9576.cpp
File metadata and controls
52 lines (42 loc) · 972 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
43
44
45
46
47
48
49
50
51
52
#include <iostream>
#include <algorithm>
#include<cstring>
#define N 1005
using namespace std;
typedef pair<int, int> pii;
pii arr[N];
int n, m;
bool book[N];
bool comp(const pii &p1, const pii &p2)
{
if (p1.second == p2.second)
return p1.first < p2.first;
return p1.second < p2.second;
}
int main()
{
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
int i, t, tc, j;
cin >> tc;
for (t = 0; t < tc; t++)
{
int ans=0;
cin >> n >> m;
for (i = 0; i < m; i++)
cin >> arr[i].first >> arr[i].second;
sort(arr, arr + m, comp);
memset(book, false, sizeof(book));
for(i=0; i<m; i++){
for(j=arr[i].first; j<=arr[i].second; j++){
if(!book[j]){
book[j]=true;
ans++;
break;
}
}
}
cout << ans << endl;
}
return 0;
}