#P4660. [BalticOI 2008] 手套 (Day2)
[BalticOI 2008] 手套 (Day2)
Description
A chemistry professor named “Acid Rain” has a dark basement with two drawers of gloves: one drawer contains left-hand gloves, and the other contains right-hand gloves. Each drawer has gloves in different colors. The professor knows how many gloves of each color are in each drawer (the counts for the same color may differ between the two drawers). It is guaranteed that he can find at least one pair of gloves of the same color.
An experiment can succeed only if the professor wears a pair of gloves of the same color (the color does not matter). Therefore, before each experiment he goes to the basement to take gloves from the drawers, hoping to get at least one same-colored pair. However, the basement is so dark that he cannot distinguish the colors of any gloves unless he leaves the basement. The professor hates going to the basement more than once, and also hates bringing a large pile of gloves back to the lab (in case there is no same-colored pair).
Task
Write a program that:
- reads from standard input the number of colors and the number of gloves of each color;
- computes the minimum total number of gloves that must be taken to guarantee that among the taken gloves there is at least one pair of the same color (and you must specify the exact number of gloves taken from each drawer);
- writes the result to standard output.
Input Format
The first line of standard input contains a positive integer , the number of different colors. The colors are numbered from to .
The second line contains non-negative integers , where is the number of gloves of color in the left-hand glove drawer.
The third line contains non-negative integers , where is the number of gloves of color in the right-hand glove drawer.
Output Format
The first line of standard output contains a single integer: the number of gloves taken from the left-hand glove drawer. The second line contains a single integer: the number of gloves taken from the right-hand glove drawer. The sum of these two numbers should be as small as possible.
If there are multiple correct answers, your program may output any one of them.
4
0 7 1 6
1 5 0 6
2
8
Hint
For of the testdata, and .
For all testdata, and .
Translated by ChatGPT 5
京公网安备 11011102002149号