SalesforceOA #19
Get Minimum Time
Estimated MediumJudge-ready
Topics (AI-labelled)Tree & Game DPBinary Search
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.
Input
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
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.
Example 1
Input:
4 1 2 2
1
Output:
6
Example 2
Input:
1 1 5 3
1
Output:
3
Example 3
Input:
8 2 1 1
1 8
Output:
6
Example notes
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.
Editorial
Loading solution…