#P10432. [JOIST 2024] 滑雪 2 / Ski 2

[JOIST 2024] 滑雪 2 / Ski 2

Problem Description

Mr. JOI manages a famous ski resort on the IOI Plateau. He decided to build a new ski resort on the neighboring KOI Plateau to celebrate the 15th anniversary of the ski resort’s opening.

The KOI Plateau has NN points, numbered from 11 to NN. Currently, the altitude of point ii (1iN1 \leq i \leq N) is HiH_i meters, and there are no ski slopes connecting any points on the plateau. Also, each point is equipped with one unused connector facility.

Mr. JOI’s goal is to build the KOI Hotel at one point on the plateau, and then build some ski slopes to connect every point on the plateau so that people can ski from any point to the hotel. More precisely, Mr. JOI will build the ski resort in the following steps:

  1. Perform the following embankment work any number of times (possibly zero): choose a point ii and increase the altitude of point ii by 11 meter. The cost of this work is KK per operation.

  2. Choose one point among the NN points and build the KOI Hotel there.

  3. Perform the following extension work any number of times (possibly zero): choose a point ii and build one connector facility at point ii. The cost of this work is CiC_i per operation.

  4. For each of the remaining N1N - 1 points other than the point where the KOI Hotel is built, do the following construction. Let ii be the index of that point. Choose another point jj whose altitude is strictly lower, and use one unused connector facility of point jj to build a one-way ski slope from point ii to point jj. Note that if there is no point jj with a strictly lower altitude and an unused connector facility, then the goal cannot be achieved.

The construction cost of the ski resort is the sum of the costs of the embankment work and the extension work.

Write a program that, given the information of each point on the KOI Plateau and the cost KK per embankment operation, finds the minimum cost to build the ski resort.

Input Format

Read the following data from standard input:

  • NN KK
  • H1H_1 C1C_1
  • H2H_2 C2C_2
  • ...
  • HNH_N CNC_N

Output Format

Output one line: the minimum cost to build the ski resort.

5 2
0 6
1 1
0 5
2 1
1 2
8
5 100000
0 6
1 1
0 5
2 1
1 2
100010
8 8
0 36
1 47
2 95
0 59
1 54
0 95
1 87
2 92
108

Hint

Sample Explanation 1

For example, the ski resort can be built as follows:

  1. Perform the embankment work twice at point 11, and once at point 55. The total cost of these embankment operations is 2×(2+1)=62 \times (2 + 1) = 6. The altitudes of the points become 2,1,0,2,22, 1, 0, 2, 2 meters.
  2. Build the KOI Hotel at point 33.
  3. Perform the extension work twice at point 22. The total cost of these extension operations is 1×2=21 \times 2 = 2. As a result, starting from point 11, the numbers of connector facilities at each point become 1,3,1,1,11, 3, 1, 1, 1.
  4. Build 44 ski slopes: one from point 11 to point 22, one from point 22 to point 33, one from point 44 to point 22, and one from point 55 to point 22.

Therefore, the cost to build the ski resort is 6+2=86 + 2 = 8. Since it is impossible to build the ski resort with cost at most 77, output 88.

The sample input satisfies the constraints of subtasks 3,4,5,63, 4, 5, 6.

Sample Explanation 2

The only difference between this sample input and Sample Input 1 is the value of KK.

This sample input satisfies the constraints of subtasks 1,3,4,5,61, 3, 4, 5, 6.

Sample Explanation 3

This sample input satisfies the constraints of subtasks 2,3,4,5,62, 3, 4, 5, 6.

Constraints

  • 1N3001 \leq N \leq 300
  • 1K1091 \leq K \leq 10^9
  • 0Hi1090 \leq H_i \leq 10^9 (1iN1 \leq i \leq N)
  • 1Ci1091 \leq C_i \leq 10^9 (1iN1 \leq i \leq N)
  • All given values are integers.

Subtasks

  • (5 points) K100,000K \geq 100,000, Hi300H_i \leq 300, Ci100C_i \leq 100 (1iN1 \leq i \leq N)
  • (12 points) H1HiH_1 \leq H_i, C1CiC_1 \leq C_i, Hi300H_i \leq 300 (1iN1 \leq i \leq N)
  • (9 points) N10N \leq 10, Hi10H_i \leq 10 (1iN1 \leq i \leq N)
  • (33 points) N40N \leq 40, Hi40H_i \leq 40 (1iN1 \leq i \leq N)
  • (27 points) Hi300H_i \leq 300 (1iN1 \leq i \leq N)
  • (14 points) No additional constraints.

Translated by ChatGPT 5