GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Friday 9 September 2022

[Solution] Pokemon Battles CodeChef Solution



Problem

There are N Pokemon trainers numbered from 1 to N. Each trainer has one Pokemon. All the trainers have arrived to participate in a contest.
There are two battle arenas, one in ground and other in water. Each Pokemon may have different power in both the arenas.
When two Pokemon fight in an arena, the Pokemon having higher power in that arena wins. It is guaranteed that all Pokemon have distinct powers in the same arena to avoid any ties.

The strength of a Pokemon trainer is determined to be the number of other Pokemon his Pokemon can defeat in at least one arena.

It is known that only the Pokemon trainers with the highest strength will qualify for the next round (multiple trainers may have the same strength). Find the number of Pokemon trainers who will qualify for the next round.

Input Format

  • The first line of input will contain a single integer T, denoting the number of test cases.
  • Each test case consists of three lines of input.
    • The first line of each test case contains a single integer N, denoting the number of Pokemon trainers.
    • The second line will contain N space-separated integers, A_{1},A_{2},\ldots,A_{N}, where A_{i} denotes the power of the Pokemon of i^{th} trainer in the ground arena.
    • The third line will contain N space-separated integers, B_{1},B_{2},\ldots,B_{N}, where B_{i} denotes the power of the Pokemon of i^{th} trainer in the water arena.

Output Format

For each test case, output on a new line the number Pokemon trainers who will qualify for the next round.


Solution Click Below:-  👉CLICK HERE👈
👇👇👇👇👇

Explanation:

Test case 1: The second trainer's Pokemon can defeat the first trainer's Pokemon in both arenas so his strength is 1. Similarly, the first trainer's Pokemon can not defeat the second trainer's Pokemon in any arena so his strength will be 0. Hence, only the second trainer will qualify.

Test case 2: The second trainer's Pokemon can defeat the first trainer's Pokemon in ground arena so his strength is 1 and the first trainer's Pokemon can defeat the second trainer's Pokemon in water arena so his strength will also be 1. Hence both of them will qualify.

No comments:

Post a Comment