Problem Statement
PROBLEM STATEMENT At the recent TopCoder Invitational, an effort was made to seat diners at the awards banquet so that the staff and the competitors mingled as much as possible. Given m members and n staffers, to be assigned to k tables each seating r people, you are to find the "best" seating arrangement according to a certain metric. Define the "imbalance" at a table as the difference between the number of staffers seated there and the number of members seated there. So a table with 9 staffers and no room for anyone else has an imbalance of 9, and a table with 5 members and 4 staffers has an imbalance of 1. Empty tables have an imbalance of 0, naturally. Define the "overall imbalance" of a seating arrangement as the worst (greatest) imbalance at any one table. Find the assignment with the minimum possible overall imbalance, and return the imbalance. Your method will be called with the four values listed above. If you cannot find *any* arrangement, that is, there are not enough seats for everyone, return -1. Tables may be left partially or completely empty. DEFINITION Class Name: Seating Method Name: best Parameters: int, int, int, int Returns: int Here is the method signature (make sure your method is public): int best(int m, int n, int k, int r); TopCoder will ensure that m, n, k, and r will all be between 0 and 1000, inclusive. EXAMPLES best(9, 0, 1, 9) = 9 best(4, 5, 1, 30) = 1 best(1, 0, 3, 4) = 1 best(8, 8, 6, 6) = 0 best(8, 8, 6, 3) = 1 best(12, 8, 6, 6) = 1 best(12, 8, 2, 10) = 2 best(300, 50, 7, 50) = 36 best(20, 20, 4, 8) = -1
Definition
- Class:
- Seating
- Method:
- best
- Parameters:
- int, int, int, int
- Returns:
- int
- Method signature:
- int best(int param0, int param1, int param2, int param3)
- (be sure your method is public)
Constraints
Examples
No public sample cases were explicitly marked for this problem in the original data.