[Solution] Pokemon Battles CodeChef Solution
Problem
There are Pokemon trainers numbered from to . 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 , 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 , denoting the number of Pokemon trainers.
- The second line will contain space-separated integers, , where denotes the power of the Pokemon of trainer in the ground arena.
- The third line will contain space-separated integers, , where denotes the power of the Pokemon of 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.
Explanation:
Test case 1: The second trainer's Pokemon can defeat the first trainer's Pokemon in both arenas so his strength is . Similarly, the first trainer's Pokemon can not defeat the second trainer's Pokemon in any arena so his strength will be . 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 and the first trainer's Pokemon can defeat the second trainer's Pokemon in water arena so his strength will also be . Hence both of them will qualify.
No comments:
Post a Comment