Locker Allocation (APCS 2018-10 Expert)
2.0s 256MThere are \(M\) lockers, and \(N\) existing customers rent \(x_i\) lockers each. A new customer needs \(S\) free lockers. You may cancel existing rentals, but each customer must be canceled entirely or retained entirely. Find the minimum total number of rented lockers to cancel so that at least \(S\) lockers become free. The answer is \(0\) if enough lockers are already free.
Input Format
The first line contains \(M,S,N\), in that order. The second contains the \(N\) rental sizes \(x_i\).
Output Format
Print the minimum number of rented lockers that must be canceled.
Constraints
\(1\le M\le100000\), \(1\le S\le M\), \(1\le N\le100\), \(x_i\ge0\), \(\sum x_i\le M\).
Sample Input
20 14 5
1 7 2 8 2
Sample Output
15
Source
APCS 2018-10 public archive version: e465。
Log in to write and submit code.
Log in