-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday_56.cpp
70 lines (54 loc) · 1.5 KB
/
day_56.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
Name - Himanshu Pokhriyal
Date - 20 May , 2024
Version - C++17
Ques-1 Team Olympiad
Link - https://codeforces.com/problemset/problem/490/A
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> programming, math, pe;
// Read the input and categorize the children by their skills
for (int i = 0; i < n; i++) {
int skill;
cin >> skill;
if (skill == 1) {
programming.push_back(i + 1); // store 1-based index
} else if (skill == 2) {
math.push_back(i + 1); // store 1-based index
} else if (skill == 3) {
pe.push_back(i + 1); // store 1-based index
}
}
// Calculate the maximum number of teams
int teams = min({programming.size(), math.size(), pe.size()});
cout << teams << endl;
// Form and print each team
for (int i = 0; i < teams; i++) {
cout << programming[i] << " " << math[i] << " " << pe[i] << endl;
}
return 0;
}
Time complexity - O(n+n/3) max value of team could be = n/3
Space complexity - O(3*n) == O(n)
Ques-2 Medium Number
Link - https://codeforces.com/problemset/problem/1760/A
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while( t-- ){
int arr[3];
for( int i=0;i<3;i++){
cin>>arr[i];
}
sort(arr,arr+3);
cout<<arr[1]<<endl;
}
}
Time complexity - O(t*3*log(3)) == O(t)
Space complexity - O(1)
*/