-
Notifications
You must be signed in to change notification settings - Fork 185
/
Copy pathactivitySelectionProblem.cpp
56 lines (44 loc) · 1.07 KB
/
activitySelectionProblem.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long
const int mod=1000000007;
#define pb push_back
#define bs binary_search
#define up upper_bound
#define lb lower_bound
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define all(x) (x).begin(),(x).end()
#define ppc __builtin_popcount
#define ppcll __builtin_popcountll
#ifdef ONLINE_JUDGE
#define cerr if (false) cerr
#endif
bool myCmp(pair <int, int> a, pair <int, int> b)
{
return (a.second < b.second);
}
int maxActivities(pair <int, int> arr[], int n)
{
sort(arr, arr + n, myCmp);
int prev = 0;
int res = 1;
for(int curr = 1; curr < n; curr++)
{
if(arr[curr].first >= arr[prev].second)
{
res++;
prev = curr;
}
}
return res;
}
int main()
{
pair <int, int> arr[] = {make_pair(12, 25), make_pair(10, 20), make_pair(20, 30)};
int n = 3;
cout<<maxActivities(arr, n);
return 0;
}