Hold the Star
시간 제한2초메모리 제한2048 MB
각 캐릭터의 시작 방과 이동 비용이 주어질 때, 별의 시작 방마다 캐릭터 m이 별을 들도록 만드는 최소 비용을 구한다.
문제
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.
입력
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 ().
출력
For each level in order, output the minimum total staracips you have to spend to win the level.