MathWorksOA #21
Job Execution
Estimated MediumJudge-ready
Topics (AI-labelled)Binary SearchGreedy
In each round, choose one task as the main task and run it for x seconds, while every other task runs for y seconds; once a task's accumulated run time reaches its required time, it finishes and leaves. Find the minimum number of rounds needed to finish all tasks. The original Markdown of the same version in the fixed source repository states y < x in full, and its rules, function signature, and constraints are the same as those of Snowflake #15.
Input
The first line contains n x y, and the second line contains n positive integers executionTime. 1≤n≤100000, 1≤executionTime[i]≤10^9, 1≤y<x≤10^9.
Output
Output the minimum number of operations needed to finish all tasks.
Example 1
Input:
5 4 2
3 4 1 7 6
Output:
3
Example 2
Input:
1 2 1
1
Output:
1
Example 3
Input:
2 3 1
10 10
Output:
6
Example notes
Binary search on the number of operations T. With T rounds, every task gets at least T·y of base execution; each main-task operation provides x−y extra toward the remaining demand, so task i still needs to be chosen as the main task ceil(max(0, executionTime[i]−T·y)/(x−y)) times. T is feasible when the total of these counts does not exceed T.
Editorial
Loading solution…