luogu#P12015. [NOISG 2025 Finals] Monsters
[NOISG 2025 Finals] Monsters
题目描述
Penguinland is an infinite number line with n monsters. The -th monster is initially at position on the number line, with health . It is guaranteed that no two monsters share the same initial position.
Today, Brian the penguin wishes to defeat all the monsters! To defeat them, Brian has planted mines at certain positions. The -th mine is located at position . Detonating a mine instantly destroys all monsters standing on that position, and each mine can be detonated any number of times. However, each detonation costs dollar. It is guaranteed that no two mines are planted at the same position.
In addition to detonating mines, Brian can also perform two types of operations:
- Move a monster left or right by unit along the number line.
- Increase or decrease a monster’s health by .
Each operation costs dollar to execute.
A monster is considered defeated if its health reaches or if it is destroyed by a mine. Help Brian find the minimum cost (in dollars) needed to defeat all the monsters.
输入格式
Your program must read from standard input.
The first line of input contains two space-separated integers and .
The following lines each contain two space-separated integers. The -th of these lines contains and .
The last line of input contains space-separated integers .
输出格式
Your program must print to standard output.
Output a single integer, the minimum cost (in dollars) needed to defeat all the monsters.
The output should contain only a single integer. Do not print any additional text such as Enter a number or The answer is.
3 1
2 2
4 5
5 4
5
4
5 2
7 7
6 3
10 4
4 4
9 1
7 10
7
10 5
19 10
5 3
1 2
3 6
17 2
20 3
8 2
12 3
14 2
15 1
40 13 37 14 6
23
提示
Subtasks
For all test cases, the input will satisfy the following bounds:
- for all
- for all
- for all
- for all
Your program will be tested on input instances that satisfy the following restrictions:
Subtask | Marks | Additional constraints |
---|---|---|
Sample test cases | ||
No additional constraints |
Sample Test Case 1 Explanation
There are monsters and mine. Brian can:
- Decrease the health of monster to , costing dollars.
- Move monster to the right by unit (changing its position from to ), costing dollar.
- Detonate the mine at position , defeating both monsters and , costing dollar.
The total cost needed is dollars.
This test case is valid for subtasks , and .
Sample Test Case 2 Explanation
This test case is valid for subtasks , and .
There are monsters and mines. Brian can:
- Decrease the health of monster to , costing dollar.
- Detonate mine , defeating monster , costing dollar.
- Move monster to the right by unit (changing its position from to ), costing dollar.
- Move monster to the right by units (changing its position from to ), costing dollars.
- Detonate mine , defeating monsters , and , costing dollar.
The total cost needed is dollars.
Sample Test Case 3 Explanation
This test case is valid for subtasks , and .