-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMax_No_Of_Activities_Array_Greedy.cpp
More file actions
66 lines (51 loc) · 1.03 KB
/
Max_No_Of_Activities_Array_Greedy.cpp
File metadata and controls
66 lines (51 loc) · 1.03 KB
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
#include<bits/stdc++.h>
using namespace std;
void maxNumberOfActivities(int st[],int fs[],int n)
{
int i,j,c=1;
pair<int, char> pairt[n];
for (i = 0;i<n;i++)
{
pairt[i].first = fs[i];
pairt[i].second = st[i];
}
// Sorting the pair array.
sort(pairt, pairt + n);
// Modifying original arrays
for (int i = 0; i < n; i++)
{
fs[i] = pairt[i].first;
st[i] = pairt[i].second;
}
// for(i=0;i<n;i++)
// cout<<st[i]<<" ";
// cout<<"\n";
// for(i=0;i<n;i++)
// cout<<fs[i]<<" ";
int prev = fs[0];
for(i=1;i<n;i++)
{
if(st[i]>=prev)
{
c++;
prev = fs[i];
}
}
cout<<c<<"\n";
}
int main() {
int t;
cin>>t;
while(t--)
{
int n,i;
cin>>n;
int st[n],fs[n];
for(i=0;i<n;i++)
cin>>st[i];
for(i=0;i<n;i++)
cin>>fs[i];
maxNumberOfActivities(st,fs,n);
}
return 0;
}