forked from sunnyshahabuddin/Coding-Ninjas
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactivity.cpp
More file actions
34 lines (32 loc) · 753 Bytes
/
activity.cpp
File metadata and controls
34 lines (32 loc) · 753 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
#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<int, int> a, pair<int, int> b) {
return a.second < b.second;
}
int main(int argc, char const *argv[])
{
int t;
cin>>t;
while(t--) {
int n, a, b;
cin>>n;
pair<int, int> arr[n];
for(int i=0;i<n;i++) {
cin>>a>>b;
arr[i] = make_pair(a, b);
}
sort(arr, arr+n, cmp);
// for(int i=0;i<n;i++) {
// cout<<arr[i].first<<" "<<arr[i].second<<endl;
// }
int ans = 1, chosen = 0;
for(int i=1;i<n;i++) {
if(arr[i].first>=arr[chosen].second) {
ans++;
chosen = i;
}
}
cout<<ans<<endl;
}
return 0;
}