Mahasena Codechef Solution

Hello Programmers In this post, you will know how to solve the Mahasena Codechef Solution. The Problem Code: AMR15A

Ezoicreport this adMahasena Codechef Solution
Mahasena Codechef Solution

One more thing to add, don’t directly look for the solutions, first try to solve the problems of Codechef by yourself. If you find any difficulty after trying several times, then you can look for solutions.

Problem

Kattapa, as you all know was one of the greatest warriors of his time. The kingdom of Maahishmati had never lost a battle under him (as army-chief), and the reason for that was their really powerful army, also called as Mahasena.

Kattapa was known to be a very superstitious person. He believed that a soldier is “lucky” if the soldier is holding an even number of weapons, and “unlucky” otherwise. He considered the army as “READY FOR BATTLE” if the count of “lucky” soldiers is strictly greater than the count of “unlucky” soldiers, and “NOT READY” otherwise.

Given the number of weapons each soldier is holding, your task is to determine whether the army formed by all these soldiers is “READY FOR BATTLE” or “NOT READY”.

Note: You can find the definition of an even number here.

Input

The first line of input consists of a single integer N denoting the number of soldiers. The second line of input consists of N space separated integers A1A2, …, AN, where Ai denotes the number of weapons that the ith soldier is holding.

Output

Generate one line output saying “READY FOR BATTLE”, if the army satisfies the conditions that Kattapa requires or “NOT READY” otherwise (quotes for clarity).

Constraints

  • 1 ≤ N ≤ 100
  • 1 ≤ Ai ≤ 100

Sample Input 1 

1
1

Sample Output 1 

NOT READY

Mahasena CodeChef Solution in JAVA

import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < A.length; i++) {
			A[i] = sc.nextInt();
		}
		System.out.println(solve(A) ? "READY FOR BATTLE" : "NOT READY");
		sc.close();
	}
	static boolean solve(int[] A) {
		return Arrays.stream(A).filter(x -> x % 2 == 0).count() > Arrays.stream(A).filter(x -> x % 2 != 0).count();
	}
}

Disclaimer: The above Problem (Mahasena) is generated by CodeChef but the solution is provided by BrokenProgrammers. This tutorial is only for Educational and Learning purposes.

Note:- I compile all programs, if there is any case program is not working and showing an error please let me know in the comment section. If you are using adblocker, please disable adblocker because some functions of the site may not work correctly.

Next: Andrew and the Meatballs again Codechef Solution

Sharing Is Caring

Leave a Comment

Ezoicreport this ad