luogu#P12015. [NOISG 2025 Finals] Monsters

[NOISG 2025 Finals] Monsters

题目描述

Penguinland is an infinite number line with n monsters. The ii-th monster is initially at position a[i]a[i] on the number line, with health h[i]h[i]. 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 kk mines at certain positions. The jj-th mine is located at position x[j]x[j]. 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 11 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 11 unit along the number line.
  • Increase or decrease a monster’s health by 11.

Each operation costs 11 dollar to execute.

A monster is considered defeated if its health reaches 00 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 nn and kk.

The following nn lines each contain two space-separated integers. The ii-th of these lines contains a[i]a[i] and h[i]h[i].

The last line of input contains kk space-separated integers x[1],x[2],,x[k]x[1], x[2], \ldots, x[k].

输出格式

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:

  • 1n,k2000001 \leq n, k \leq 200\,000
  • 1a[i],h[i]1091 \leq a[i], h[i] \leq 10^9 for all 1in1 \leq i \leq n
  • 1x[i]1091 \leq x[i] \leq 10^9 for all 1ik1 \leq i \leq k
  • a[i]a[j]a[i] \neq a[j] for all iji \neq j
  • x[i]x[j]x[i] \neq x[j] for all iji \neq j

Your program will be tested on input instances that satisfy the following restrictions:

Subtask Marks Additional constraints
00 Sample test cases
11 1414 k=1k = 1
22 66 k=2k = 2
33 1010 n,k18n, k \leq 18
44 3030 n,k3000n, k \leq 3000
55 2929 h[i]=109h[i] = 10^9
66 1111 No additional constraints

Sample Test Case 1 Explanation

There are n=3n = 3 monsters and k=1k = 1 mine. Brian can:

  • Decrease the health of monster 11 to 00, costing 22 dollars.
  • Move monster 22 to the right by 11 unit (changing its position from 44 to 55), costing 11 dollar.
  • Detonate the mine at position 55, defeating both monsters 22 and 33, costing 11 dollar.

The total cost needed is 2+1+1=42 + 1 + 1 = 4 dollars.

This test case is valid for subtasks 1,3,41, 3, 4, and 66.

Sample Test Case 2 Explanation

This test case is valid for subtasks 2,3,42, 3, 4, and 66.

There are n=5n = 5 monsters and k=2k = 2 mines. Brian can:

  • Decrease the health of monster 55 to 00, costing 11 dollar.
  • Detonate mine 22, defeating monster 33, costing 11 dollar.
  • Move monster 22 to the right by 11 unit (changing its position from 66 to 77), costing 11 dollar.
  • Move monster 44 to the right by 33 units (changing its position from 44 to 77), costing 33 dollars.
  • Detonate mine 11, defeating monsters 1,21, 2, and 44, costing 11 dollar.

The total cost needed is 1+1+1+3+1=71 + 1 + 1 + 3 + 1 = 7 dollars.

Sample Test Case 3 Explanation

This test case is valid for subtasks 3,43, 4, and 66.