A ground station broadcasts a shared calibration beam to a small fleet of n satellites. The beam starts at output rate 1 unit per minute, and every satellite draws from the same shared energy pool, which begins empty and grows by the current beam rate every minute. Satellite i needs its pool exposure to reach at least c_i units before it can be calibrated. At any whole-minute mark when the pool holds at least c_i units, the station may choose to calibrate satellite i: doing so immediately drains the pool back to zero and permanently increases the beam's rate by a fixed amount K, effective from that same minute onward, in exchange for one fewer satellite competing for bandwidth. Each satellite is calibrated exactly once, and the station chooses the order of calibration.
Given the beam's rate increment K and each satellite's requirement, determine the minimum total number of minutes needed to calibrate every satellite, choosing the calibration order that minimizes this total.
Line 1: two space-separated integers n and K — the number of satellites and the fixed amount by which the beam's rate increases after each calibration. Line 2: n space-separated integers c_1 ... c_n — the calibration requirement of each satellite.
Print a single integer: the minimum total number of minutes needed to calibrate all n satellites under an optimal calibration order.
Example 1
Input
2 1 3 4
Expected
5
Explanation
Calibrating satellite 1 (requirement 3) first: at rate 1 it takes ceil(3/1)=3 minutes. This raises the rate to 1+1=2, so satellite 2 (requirement 4) then takes ceil(4/2)=2 more minutes, for a total of 5. Calibrating satellite 2 first instead would take ceil(4/1)=4 minutes, then ceil(3/2)=2 more for satellite 1, totaling 6, which is worse. The minimum over both orders is 5.
Example 2
Input
3 2 1 1 1
Expected
3
Explanation
All three satellites need only 1 unit, so the order does not matter. The first calibration takes ceil(1/1)=1 minute at rate 1; the rate then becomes 1+2=3, so the second calibration takes ceil(1/3)=1 minute; the rate becomes 1+4=5, so the third takes ceil(1/5)=1 minute. The total is 1+1+1=3.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →