Ladder Game
Time limit1sMemory limit128 MB
Given a ladder with n lines and m rungs, erase at most one rung to minimize the sum of scores reached from the leftmost k starting lines.
- Level
Hard8 of 10
- Topics
- Implementation, Simulation, Array, Sorting
- Solved
- No attempts yet
Problem
Sanggeun is playing a ladder game. The ladder consists of vertical lines and horizontal bars. The vertical lines are numbered from to , left to right, and a positive integer is written at the bottom of vertical line .
Starting from the top of vertical line and following the ladder downward, you arrive at some cell at the bottom; the number written in that cell is the score you get for choosing vertical line .
Sanggeun chooses the leftmost consecutive vertical lines, that is, lines through . The sum of the scores obtained from the chosen lines is Sanggeun's score.
Sanggeun may erase at most one horizontal bar. If a bar is erased, each vertical line's destination cell is recomputed on the ladder that remains after the removal.
Given the shape of the ladder and the number of chosen vertical lines , write a program that finds the smallest score Sanggeun can obtain.
Input
The first line contains the number of vertical lines (), the number of horizontal bars (), the vertical length of the ladder (), and the number of chosen vertical lines ().
Each of the next lines contains the score written at the bottom of a vertical line, one per line. ()
Each of the next lines contains two integers and describing a bar's position. (, ) Bar connects vertical lines and , and its distance from the top of the ladder is .
Output
Print the smallest score Sanggeun can obtain on the first line.