File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import java .util .*;
2+
3+ public class JavelinQualification
4+ {
5+ public static void main (String [] args ) throws java .lang .Exception
6+ {
7+ // your code goes here
8+ Scanner sc = new Scanner (System .in );
9+ int t = sc .nextInt ();
10+ while (t -->0 ){
11+ int n = sc .nextInt ();
12+ int m = sc .nextInt ();
13+ int x = sc .nextInt ();
14+ int [] arr = new int [n ]; // creating array which stores throws of each player
15+ int [] player = new int [n ];
16+ int count = 0 ;
17+ HashMap <Integer ,Integer > map = new HashMap <>();
18+ int index = 0 ;
19+ for (int i = 0 ; i < n ; i ++){
20+ arr [i ] = sc .nextInt ();
21+ map .put (arr [i ],i +1 );
22+ if (arr [i ]>=m ){ // if the throw is qualified
23+ player [index ] = i +1 ; // storing selected players in 'player' array
24+ arr [i ] = 0 ;
25+ count ++; // storing count of qualified players
26+ x --;
27+ index ++;
28+ }
29+ }
30+ while (x -->0 ){ // getting remaining x player who are left
31+ int max1 = map .getOrDefault (max (arr , n ),0 ); // creating variable to get index of maximum of the remaining players
32+ if (arr [max1 -1 ]>0 ){ // checking if the player is not selected
33+ player [index ] = max1 ;
34+ arr [max1 -1 ] = 0 ;
35+ count ++;
36+ index ++;
37+ }
38+ }
39+ Arrays .sort (player ); // sorting player in increasing order
40+ System .out .print (count +" " );
41+ for (int i = 0 ; i < n ; i ++){
42+ if (player [i ]!=0 ){ // if the player is qualified
43+ System .out .print (player [i ]+" " );
44+ }
45+ }
46+ System .out .println ();
47+ }
48+ sc .close ();
49+ }
50+ static int max (int [] arr , int n ){ // funtion to get maximum throw
51+ int max = Integer .MIN_VALUE ;
52+ for (int i = 0 ; i < n ; i ++){
53+ if (max <arr [i ]){
54+ max =arr [i ];
55+ }
56+ }
57+ return max ;
58+ }
59+ }
You can’t perform that action at this time.
0 commit comments