-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathBUSYMAN.cpp
35 lines (29 loc) · 826 Bytes
/
BUSYMAN.cpp
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
/*
greedy
difficulty: easy
date: 23/Apr/2020
problem: compute the maximum number of activities (each with start and end times) that you can do without overlapping them (one at a time)
hint: sort the activites by increasing end time
by: @brpapa
*/
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii; // start, end
// p1 < p2
bool cmp(const ii p1, const ii p2) {
return p1.second < p2.second;
}
int main() {
int T; cin >> T;
while (T--) {
int N; cin >> N;
vector<ii> time(N); for (ii &t : time) cin >> t.first >> t.second;
sort(time.begin(), time.end(), cmp);
int ans = 1; ii curr = time[0];
for (int i = 1; i < N; i++)
if (time[i].first >= curr.second)
ans++, curr = time[i];
cout << ans << endl;
}
return 0;
}