[Hacker Earth] Amazon SDE Challenge - April/ May 2022 - Cricket Training Program

Amazon SDE Challenge - April/ May 2022

Cricket Training Program

Cricket training program

Bob is the coach of a cricket team and he has N players each having a training capacity of A, He also has M trainers with training capacity 6 which can train players for their better performance Any trainer can train only one player and one player can take training from only one trainer. Bob wants the maximum number of players from his team to get training from trainers But the players can only take training from the trainer if the trainer’s training capacity B,(1SISM) is less than or equal to the training capacity of that player A.

Task

Determine the maximum number of players who can take training if trainers are assigned optimally.

Notes

  • There can multiple players or trainers with the same training capacities.
  • You have to output only the count of players who can get training from trainers.
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
#include <bits/stdc++.h>

#define MAX_N 100001
#define ll long long
#define pll pair<ll, ll>
#define vpll vector<pll>
#define vll vector<ll>
#define vvll vector<vll>
#define vs vector<string>
#define vvs vector<vs>
#define usll unordered_set<ll>
#define all(a) begin(a), end(a)
using namespace std;

ll n, m;

ll solve(vll& A, vll& B) {
sort(all(A));
sort(all(B));
ll res = 0, i = 0, j = 0, n = A.size(), m = B.size();
while(i < n and j < m) {
if(A[i] >= B[j]) {
i++,j++,res++;
} else i++;
}
return res;
}

int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
ll tc;
cin>>tc;
while(tc--) {
cin>>n>>m;
vll A(n), B(m);
for(ll i = 0; i < n; i++) cin>>A[i];
for(ll i = 0; i < m; i++) cin>>B[i];
cout<<solve(A,B)<<'\n';
}
return 0;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2022/04/23/PS/HackerEarth/cricket-training-program/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.