QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 64 MB 満点: 20

#23786. あみだくじ

統計

問題

あなたは J 君と一緒にあみだくじを使って遊んでいる.あみだくじは $n$ 本の縦棒と $m$ 本の横棒からなる.縦棒には左から順に $1$ から $n$ の番号がついており,縦棒 $i$ の下端には正整数 $s_i$ が書かれている.

problem_23786_413728510307925eaac8a03e9b29e566.png

図 3-1:あみだくじの例($n = 4, m = 5, s_1 = 20, s_2 = 80, s_3 = 100, s_4 = 50$)

縦棒 $i$ の一番上から順に道をたどっていき到達した下端に書かれている整数が,縦棒 $i$ を選んだ場合の得点である.例えば,図 3-1 では,縦棒 $1$ を選ぶと得点は $80$ 点であり,縦棒 $2$ を選ぶと得点は $100$ 点である.

problem_23786_cd531911d1f931ecb867348e85507522.png

図 3-2:道のたどり方の例

J 君は縦棒 $1$ から縦棒 $k$ までの連続した $k$ 本を選ぶことにした.それら $k$ 本の縦棒を選んだときの点数の合計が J 君の得点となる.ただし,あなたはあみだくじ内の横棒を一本選び,その横棒をあみだくじから削除することができる(削除しなくてもよい.)もし,あなたが横棒を一本削除した場合は,削除後のあみだくじにおいて,縦棒 $1$ から縦棒 $k$ までの連続した $k$ 本の縦棒を選んだときの点数の合計が J 君の得点となる.

入力としてあみだくじの形と J 君の選ぶ縦棒の本数 $k$ が与えられたとき,J 君の得点の最小値を求めるプログラムを作成せよ.

入力

  • $1$ 行目には $4$ つの整数 $n, m, h, k$ が空白区切りで書かれている.$n$($2 \le n \le 1000$)は縦棒の本数を,$m$($1 \le m \le 100000$)は横棒の本数を,$h$($2 \le h \le 1000$)は縦棒の長さを,$k$($1 \le k \le n$)は J 君が選ぶ縦棒の本数を表す.
  • 続く $n$ 行には縦棒の下端に書かれている点数が書かれている.$(i + 1)$ 行目($1 \le i \le n$)には正整数 $s_i$ が書かれている.また,$s_1 + s_2 + \cdots + s_n \le 2000000000 = 2 \times 10^9$ を満たす.
  • 続く $m$ 行には横棒の位置が書かれている.横棒には $1$ から $m$ までの番号がついている.$(i + n + 1)$ 行目($1 \le i \le m$)には,横棒 $i$ の位置を表す $2$ つの整数 $a_i, b_i$($1 \le a_i \le n - 1, 1 \le b_i \le h - 1$)が空白区切りで書かれており,横棒 $i$ が縦棒 $a_i$ と縦棒 $a_i + 1$ を結び,横棒 $i$ の上端からの距離が $b_i$ であることを表す.ただし,どの $2$ つの横棒も端点を共有することはない.

採点用データのうち,配点の $20\%$ 分は横棒を削除しない場合に J 君の得点が最少となる.また,配点の $30\%$ 分は $n \le 20, m \le 30, h \le 10$ を満たし,配点の $60\%$ 分は $m \le 1000$ を満たす.

出力

J 君の得点の最小値のみを含む $1$ 行からなる.

Sample 1

4 5 7 2
20
80
100
50
1 1
2 6
2 3
1 5
3 1
100

Sample 2

2 2 5 1
10
20
1 1
1 3
10

入出力の例の説明

例 1 は図 3-1 に対応し,あなたが横棒 $4$(縦棒 $1$ と縦棒 $2$ を上端から距離 $5$ の場所で結ぶ横棒)を削除したとき,J 君の得点は最小になる.例 2 では,あなたが横棒を削除しない場合に J 君の得点が最小になる(図 3-3 を見よ.)

problem_23786_40bb334e7b8dfce700e74ba635dfb575.png

図 3-3

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.