luogu#P5044. [IOI 2018] meetings 会议
[IOI 2018] meetings 会议
Background
This is an interactive problem, but here you should submit a complete program.
Problem Description
There are mountains arranged in a horizontal line, numbered from to from left to right. The height of mountain is (). Exactly one person lives on the top of each mountain.
You plan to hold meetings, numbered from to . The participants of meeting () are the people living on mountains from to (including and ) (). For this meeting, you must choose some mountain as the meeting location (). The cost of holding the meeting depends on your choice, and is computed as follows:
-
The cost for each participant coming from a mountain () equals the maximum height among all mountains between and (including and ). In particular, the cost for the participant from mountain is , i.e. the height of mountain .
-
The cost of the meeting equals the sum of the costs of all its participants.
You want to hold each meeting with the minimum possible cost.
Note that all participants return to their own mountains after each meeting, so the cost of a meeting is not affected by previous meetings.
Input Format
The first line contains two positive integers and , as described above.
The second line contains positive integers , representing the heights of the mountains.
Line () contains two integers , describing the participant range of the meeting.
Output Format
Output lines. Line () contains one integer , the minimum possible cost of holding meeting .
4 2
2 4 3 5
0 2
1 3
10
12
3 3
2 1 2
0 0
0 1
0 2
2
3
5
5 1
1000000000 1000000000 1 1000000000 1000000000
0 4
4000000001
15 10
10 71 84 33 6 47 23 25 52 64 70 31 22 31 2
5 10
3 7
0 13
8 12
0 0
1 3
7 13
1 13
10 12
1 1
281
180
828
263
10
201
364
744
123
71
Hint
Explanation of Sample #1
Meeting has and , so it will be attended by the people living on mountains , , and . If mountain is chosen as the meeting location, the cost of meeting is computed as follows:
- The cost for the participant from mountain is .
- The cost for the participant from mountain is .
- The cost for the participant from mountain is .
- Therefore, the total cost of meeting is .
It is not possible to hold meeting at a lower cost, so the minimum cost of meeting is .
Meeting has and , so it will be attended by the people living on mountains , , and . If mountain is chosen as the meeting location, the cost of meeting is computed as follows:
- The cost for the participant from mountain is .
- The cost for the participant from mountain is .
- The cost for the participant from mountain is .
- Therefore, the total cost of meeting is .
It is not possible to hold meeting at a lower cost, so the minimum cost of meeting is .
Constraints
Subtasks
- (4 points) .
- (15 points) .
- (17 points) $N\leq100\space000,Q\leq100\space000,H_i\leq2(0\leq i\leq N-1)$.
- (24 points) $N\leq100\space000,Q\leq100\space000,H_i\leq20(0\leq i\leq N-1)$.
- (40 points) No additional constraints.
Author
Riku Kawasaki (Japan).
Source
IOI 2018 D2T3.
Translated by ChatGPT 5