Heaps: Gladiator Strength In a fighting tournament, every gladiator fights with another gladiator, and every gladiator h
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
Heaps: Gladiator Strength In a fighting tournament, every gladiator fights with another gladiator, and every gladiator h
Sample Input 5 29418 -- denotes the total number of gladiators N denotes the strengths of N gladiators Constraints 1 <= N <= 30 1 <= Ai <= 1000. Output Format The output contains an integer denoting the minimum strength that the winning gladiator can have. If no gladiator is left, print 0. Sample Output 0 Explanation 1st fight is between gladiators with strengths 9 & 8. After the fight, the gladiator with strength 8 is eliminated and the opponent's strength is reduced to 1. The array becomes [2,1,4,1,0]. 2nd fight is between gladiators with strengths 4 & 2. After the fight, the gladiator with strength 2 is eliminated and the opponent's strength is reduced to 2. The array becomes [0,1,2,1,0]. 3rd fight is between gladiators with strengths 2 & 1. After the fight, the gladiator with strength 1 is eliminated and the opponent's strength is reduced to 1. The array becomes [0,0,1,1,0]. 4th fight, which is the last fight, is between gladiators with strengths 1 & 1. Both are eliminated. The array becomes [0,0,0,0,0]. Since there are no gladiators left, the output is 0.
1 import java.util.*; 2 import java.io.*; 3 import java.lang.Math; 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 public class Main{ public static int lastGladiatorStrength(int n, int[] A) { //this is default OUTPUT. You can change it. int result = -404; //write your Logic here: } } return result; public static void main (String[] args) { Scanner sc = new Scanner(System.in); // INPUT [uncomment & modify if required] int N = sc.nextInt (); int[] A = new int [N]; for (int i = 0; i < N; i++) { A = sc.nextInt (); } } sc.close(); System.out.print(lastGladiatorStrength (N, A));