#P16623. [GKS 2017 #C] The 4M Corporation
[GKS 2017 #C] The 4M Corporation
题目描述
The 4M Corporation has hired you to organize their departments and allocate headcount. You will create at least one department, and each department will receive some positive integer number of employees. It will not be easy, though — you have four different bosses, and each has given you a different instruction:
- The department with the fewest employees must have exactly MINIMUM employees.
- The department with the most employees must have exactly MAXIMUM employees.
- The average number of employees across all departments must be exactly MEAN.
- The median of the number of employees across all departments must be exactly MEDIAN. As a reminder, the median of a list is the value that, when the list is sorted in nondecreasing order, is in the center (for a list of odd length) or is the average of the two values in the center (for a list of even length).
Moreover, for the sake of efficiency, it is best to avoid creating too many departments. What is the smallest number of departments that you can create, if it is possible to satisfy your bosses' requests?
输入格式
The first line of the input gives the number of test cases, . test cases follow. Each consists of four integers: MINIMUM, MAXIMUM, MEAN, and MEDIAN, in that order.
输出格式
For each test case, output one line containing Case #x: y, where is the test case number (starting from 1), and is either the minimum possible number of departments, or IMPOSSIBLE if it is impossible to satisfy all four bosses' requests.
5
6 4 5 1
7 7 8 8
2 2 2 2
3 7 5 5
1 4 3 4
Case #1: IMPOSSIBLE
Case #2: IMPOSSIBLE
Case #3: 1
Case #4: 2
Case #5: 3
提示
Sample Case #1 is IMPOSSIBLE because the maximum value cannot be smaller than the minimum value.
Sample Case #2 is IMPOSSIBLE because the mean and median cannot be larger than the maximum value.
In Sample Case #3, you can create a single department with employees. This satisfies all four bosses: the department with the fewest employees has exactly , the department with the most employees has exactly , and the mean and median are both .
In Sample Case #4, you can create one department with employees and another department with employees. Note that it would not suffice to create only one department with employees, because then the department with the fewest employees would not have exactly and the department with the most employees would not have exactly .
For Sample Case #5, you can create one department with employee and two more departments with employees each.
Limits
.
Small dataset (Test set 1 - Visible)
.
.
.
.
The constraints for the Small dataset guarantee that the answer is either IMPOSSIBLE or is less than .
Large dataset (Test set 2 - Hidden)
.
.
.
.