MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / main

Function main

CodeChef_problems/ICPC_Selection/solution.cpp:14–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12ll power(ll x,ll y,ll p){ll res=1;x=x%p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
13ll MAX=1e18 , MIN=-1e18 , MOD=1000000007;
14int main()
15{
16 fastio
17 int t; cin>>t;
18 while(t--)
19 {
20 ll n,m,k,i,cnt=0; cin>>n>>m>>k;
21 string h,c; map<string,ll>mp1; vector<ll>v[n];
22 vector<pair<string,string>>vt; vector<ll>v1;
23 for(i=0;i<n;i++)
24 {
25 cin>>h>>c;
26 vt.pb({h,c}); //making pair of team-name and institute-name
27
28 v[mp1[c]].pb(i); mp1[c]++;
29 /*mp1 is used to store total no. of team particiated from a single college.
30 Since rankings are given in order so we store position of each team
31 and v[mp1[c]] is represent the mp1[c] member of any institute.
32 So team selected from first stages will be in same index so it will also
33 arrange ranking ordre.*/
34 }
35 for(i=0;i<k;i++) // Since from each institue total 'k' no. of teams possible
36 {
37 for(auto j: v[i])
38 {
39 v1.pb(j);cnt++;
40 if(cnt==m) break; //if 'm' team selected break
41 }
42 if(cnt==m) break; //if 'm' team selected break
43 }
44 // total 'm' teams will be selected for onsite round so checking it with if-else
45 if(cnt==m)
46 {
47 sort(v1.begin(),v1.end());
48 //team names printed in ascending order of ranking so sort them
49 for(auto i: v1)
50 cout<<vt[i].F<<lc;
51 cout<<lc;
52 }
53 else cout<<"Impossible"<<lc<<lc;
54 }
55 return 0;
56}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected