Problem 3: Distributing Ballot Boxes
https://open.kattis.com/problems/ballotboxes
Key Idea 1:
Given an integer representing the maximum number of people assigned to one ballot box, we can calculate the minimum number of ballot boxes needed for each city given its population. In particular, is a feasible maximum number of people assigned to one box if the sum of the minimum number of ballot boxes needed for each city is not bigger than . In other words,
For each test case, we want to find the smallest that satisfies the above equation.
Linear Approach:
For to , compute the sum of the minimum number of ballot boxes needed for each city and take the first whose sum is less than or equal to .
This approach has a time complexity of . Since , this is too slow.
Key Idea 2:
If is not a feasible maximum number of people assigned to one box, then all integers less than are also not a feasible maximum number of people.
However, if is a feasible maximum number of people assigned to one box, then all integers greater than cannot be the maximum number of people assigned to one box in the most efficient assignment.
Therefore, we can find find the smallest that satisfies the above equation using binary search.
Last updated