cswork / OA打开练习工作台

MathWorksOA #21

Job Execution

估计中等可在线判题

考点(AI 标注)二分查找贪心调度

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.

输入格式

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 the minimum number of operations needed to finish all tasks.

样例 1

输入:

5 4 2
3 4 1 7 6

输出:

3

样例 2

输入:

1 2 1
1

输出:

1

样例 3

输入:

2 3 1
10 10

输出:

6

样例说明

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.