cswork / OA打开练习工作台

AmazonOA #263

Maximize Pages Before Suspension

估计中等可在线判题

考点(AI 标注)贪心调度哈希计数

All printers start idle. Each time, activate one idle printer, which immediately prints its pages pages; then, if the number of active printers at that moment is x, every printer with threshold≤x is immediately and permanently paused, including idle printers that have not been activated yet; paused printers cannot be activated again, and the active count drops accordingly. Find the maximum total number of pages printed. The source's main sentence mistakenly wrote threshold<x, but the Note and all three complete examples consistently use ≤, and the second and third examples clearly show that idle printers are paused too; this site publicly corrects the statement on that basis.

输入格式

The first line contains n, the second line pages, and the third line threshold. The original text had no numeric bounds; this site uses 1≤n≤200000, 1≤pages[i]≤10^9, 1≤threshold[i]≤n.

输出格式

Output a single integer, the answer.

样例 1

输入:

5
4 1 5 2 3
3 3 2 3 3

输出:

14

样例 2

输入:

6
2 4 4 4 5 3
1 3 1 3 3 2

输出:

20

样例 3

输入:

4
2 6 10 13
2 1 1 1

输出:

15

样例说明

The answers are 14, 20 and 15. In the third example, printing 13 pages first permanently pauses every printer with threshold 1, after which only the 2 pages of the threshold-2 printer can still be printed.