#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 points, numbered from to . Currently, the altitude of point () is 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:
-
Perform the following embankment work any number of times (possibly zero): choose a point and increase the altitude of point by meter. The cost of this work is per operation.
-
Choose one point among the points and build the KOI Hotel there.
-
Perform the following extension work any number of times (possibly zero): choose a point and build one connector facility at point . The cost of this work is per operation.
-
For each of the remaining points other than the point where the KOI Hotel is built, do the following construction. Let be the index of that point. Choose another point whose altitude is strictly lower, and use one unused connector facility of point to build a one-way ski slope from point to point . Note that if there is no point 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 per embankment operation, finds the minimum cost to build the ski resort.
Input Format
Read the following data from standard input:
- ...
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:
- Perform the embankment work twice at point , and once at point . The total cost of these embankment operations is . The altitudes of the points become meters.
- Build the KOI Hotel at point .
- Perform the extension work twice at point . The total cost of these extension operations is . As a result, starting from point , the numbers of connector facilities at each point become .
- Build ski slopes: one from point to point , one from point to point , one from point to point , and one from point to point .
Therefore, the cost to build the ski resort is . Since it is impossible to build the ski resort with cost at most , output .
The sample input satisfies the constraints of subtasks .
Sample Explanation 2
The only difference between this sample input and Sample Input 1 is the value of .
This sample input satisfies the constraints of subtasks .
Sample Explanation 3
This sample input satisfies the constraints of subtasks .
Constraints
- ()
- ()
- All given values are integers.
Subtasks
- (5 points) , , ()
- (12 points) , , ()
- (9 points) , ()
- (33 points) , ()
- (27 points) ()
- (14 points) No additional constraints.
Translated by ChatGPT 5