Ladder Game

Time limit1sMemory limit128 MB

Summary
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 nn vertical lines and mm horizontal bars. The vertical lines are numbered from 11 to nn, left to right, and a positive integer sis_i is written at the bottom of vertical line ii.

Starting from the top of vertical line ii 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 ii.

Sanggeun chooses the leftmost consecutive vertical lines, that is, lines 11 through kk. 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 kk, write a program that finds the smallest score Sanggeun can obtain.

Input

The first line contains the number of vertical lines nn (2≤n≤10002 \le n \le 1000), the number of horizontal bars mm (1≤m≤100 0001 \le m \le 100\,000), the vertical length of the ladder hh (2≤h≤10002 \le h \le 1000), and the number of chosen vertical lines kk (1≤k≤n1 \le k \le n).

Each of the next nn lines contains the score sis_i written at the bottom of a vertical line, one per line. (s1+s2+⋯+sn≤2×109s_1 + s_2 + \cdots + s_n \le 2 \times 10^9)

Each of the next mm lines contains two integers aia_i and bib_i describing a bar's position. (1≤ai≤n−11 \le a_i \le n-1, 1≤bi≤h−11 \le b_i \le h-1) Bar ii connects vertical lines aia_i and ai+1a_i+1, and its distance from the top of the ladder is bib_i.

Output

Print the smallest score Sanggeun can obtain on the first line.

Examples2

  1. Example 1

    Input
    4 5 7 2
    20
    80
    100
    50
    1 1
    2 6
    2 3
    1 5
    3 1
    
    Expected output
    100
    
  2. Example 2

    Input
    2 2 5 1
    10
    20
    1 1
    1 3
    
    Expected output
    10