Sherlock Holmes
Time limit1sMemory limit128 MB
Split n boxes into two equal groups so that one ball color is a strict majority in both groups, and output that color with the maximum of the smaller group's majority percentage, or report no solution.
- Level
Medium6 of 10
- Topics
- Sorting, Greedy, Implementation
- Solved
- No attempts yet
Problem
Sherlock Holmes, the well-known detective, must solve a tricky situation. He has boxes (where is even), each containing exactly balls. The balls are white or black. A box contains white balls and black balls (so ).
He must partition the boxes into two groups of boxes each, so that either the white balls or the black balls form a majority (strictly more than half of that group's balls) in both groups. If such a color exists, let and be the percentage of the majority color's balls in each group. Holmes must find the maximum possible value of . Can you help him?
Input
The input consists of several data sets, each describing one collection of boxes. A data set starts with the number of boxes (). Then comes the number of balls () contained in each box, followed by, for every box, the number of white balls and the number of black balls (each ) in this order. All numbers may be separated by arbitrary white space. The input is always correct and terminates at end of file.
Output
For each data set, print the result on its own line. If a majority color exists, print that color (W for white, B for black), a single space, and the maximum value of rounded to two decimal places. Otherwise print No solution.