cswork / OA打开练习工作台

SalesforceOA #19

Get Minimum Time

估计中等可在线判题

考点(AI 标注)树形博弈二分查找

n 1-based processes form a contiguous interval. An interval of length greater than 1 may be split into two equal halves that are assigned further; alternatively, the interval may be executed directly. If it contains no high-priority process, the cost is normal_time; otherwise, the cost is priority_time×number of high-priority processes×interval length. The total time is the sum of all processor costs, not the maximum.

输入格式

The first line contains n k normal_time priority_time, and the second line contains k high-priority indices. Original ranges: 1≤n≤10⁹ with n a power of 2, 1≤k≤min(n,100000), indices in 1..n. On this site the indices in a valid process list are distinct; the original text gives no range for the time factors, and this site uses 1..10⁹ for both.

输出格式

Output the minimum total cost. An intermediate direct cost may exceed 64 bits, so use a sufficiently wide integer; do not allocate arrays proportional to n.

样例 1

输入:

4 1 2 2
1

输出:

6

样例 2

输入:

1 1 5 3
1

输出:

3

样例 3

输入:

8 2 1 1
1 8

输出:

6

样例说明

The answers are 6, 3, and 6; in the third example, the two endpoints can each be split down to single points, while the empty intervals in between are paid for.