-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path103_activity_selection_greedy.cpp
More file actions
69 lines (57 loc) · 1000 Bytes
/
Copy path103_activity_selection_greedy.cpp
File metadata and controls
69 lines (57 loc) · 1000 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// https://practice.geeksforgeeks.org/problems/activity-selection/0
#include <bits/stdc++.h>
using namespace std;
bool mycomp(vector<int> &a, vector<int> &b)
{
return a[1] < b[1];
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
vector< vector<int> > a(n);
for (int i = 0; i < n; ++i)
{
a[i].resize(2);
cin >> a[i][0];
}
for (int i = 0; i < n; ++i)
cin >> a[i][1];
sort(a.begin(), a.end(), mycomp);
/*for (int i = 0; i < n; ++i)
{
cout << a[i][0] << " " << a[i][1] << endl;
}*/
int cnt = 0, flg = 0;
int last_finish, cur_start;
for (int i = 0; i < n; ++i)
{
if (!flg)
{
cnt++;
last_finish = a[i][1];
flg = 1;
}
else
{
if (a[i][0] >= last_finish)
{
cnt++;
last_finish = a[i][1];
}
}
}
cout << cnt << endl;
}
return 0;
}