The Will Rogers Phenomenon
InterviewTime limit1sMemory limit1024 MB
Given two groups of positive integers, find one number whose move to the other group raises the average of both groups, or report that none exists.
- Level
Easy3 of 10
- Topics
- Brute force, Math
- Solved
- No attempts yet
Problem
Will Rogers (1879-1935) was an American comedian known for the following quote:
"When the Okies left Oklahoma and moved to California, they raised the average intelligence level in both states."
This apparent paradox, where moving one element from one set to another raises the average in both sets, is called the Will Rogers phenomenon. Write a program that reads two groups A and B, each containing at least two and at most ten positive integers. It must decide whether moving one number from one group to the other can raise the average in both groups. If it can, the program prints which number to move and which group to move it to.
Input
The first line contains two integers: the number of elements in the first group and the number of elements in the second group. Both values are between 1 and 10. The next line contains the numbers of the first group, and the line after that contains the numbers of the second group.
All numbers are between and .
Output
If moving one number from one group to the other raises the average in both groups, print one line with the number to move and the group it goes to, written as A or B. If several moves work, printing any one of them is enough.
If no such move exists, print NEJ.
Hint
In the first sample, the averages before any move are for A and for B. After moving the number from B to A, the averages are for A and for B.
In the second sample, the phenomenon cannot occur. For example, moving the number from A to B raises the average in A, but the average in B stays the same.