#P15497. [ICPC 2025 APC] Hold the Star
[ICPC 2025 APC] Hold the Star
Description
You are playing a computer game with rooms, characters, and one star. The rooms are arranged from left to right and numbered from to in that order. The characters are numbered from to . At any time, each character is in one of the rooms and the star is either in one of the rooms or held by one of the characters. The objective of the game is for the star to be held by character .
You can play the game by performing several actions. Each action costs a certain amount of staracips (the unit of currency in the game), possibly zero. In each action, you choose a character (let room be the room the character is currently in) and command the character to do either of the following:
- Move to one of the adjacent rooms ( or ), if such a room exists. If character is holding the star, then the character continues to hold the star. This action costs staracips. The values of are given.
- Pick the star up and hold it, if the star is currently in room and is not held by any character. This action costs staracips.
- Put the star down and release it, if the star is currently held by character . The star then falls to room . This action costs staracips.
The game contains levels, numbered from to . In all levels, each character is initially in room and character must hold the star to win the level. The only difference between the levels is that, in each level , the star is initially in room .
For each level, you want to compute the minimum total staracips you have to spend to win the level. Note that you don’t have to minimize the number of actions.
Input Format
The first line of input contains three integers , , and (; ; ). The -th of the next lines contains two integers and (; ). The -th of the next lines contains an integer ().
Output Format
For each level in order, output the minimum total staracips you have to spend to win the level.
6 5 4
1 7
3 2
2 3
5 3
2 5
1
2
5
6
5
0
8
14
Hint
Explanation for the sample input/output #1
You can win the first level by spending staracips by doing the following actions:
- Character moves from room to room . This action costs staracips.
- Character picks the star up.
You can win the second level by spending staracips by doing the following actions:
- Character picks the star up.
You can win the third level by spending staracips by doing the following actions:
- Character picks the star up.
- Character moves from room to room . This action costs staracips.
- Character moves from room to room . This action costs staracips.
- Character puts the star down.
- Character picks the star up.
- Character moves from room to room . This action costs staracips.
- Character puts the star down.
- Character picks the star up.
You can win the fourth level by spending staracips by doing the following actions:
- Character moves from room to room , then to room , then to room . These actions cost staracips in total.
- Character picks the star up.
- Character moves from room to room , then to room , then to room , then to room . These actions cost staracips in total.
- Character puts the star down.
- Character picks the star up.
京公网安备 11011102002149号