AtCoder Grand Contest 073
D
Four Jewels
AtCoder
未评级
原题
← C→
翻译中…

Problem Statement

翻译中…

In this world, there are $K$ types of gems numbered from $1$ to $K(=4)$. The value per unit size of a gem of type $i$ is $W_i$.

翻译中…

Snuke has $N$ gems. The $i$-th gem is of type $A_i$ and has size $B_i$. Also, Snuke has $N$ boxes, where the $i$-th box has size $i$.

翻译中…

Snuke will now put one gem in each box. When a gem's size is larger than the box, the gem is cut to fit in the box. That is, when gem $i$ is put in box $j$, its value becomes $W_{A_i} \times \min(B_i, j)$.

翻译中…

Find the maximum possible sum of gem values.

翻译中…

Constraints

翻译中…
  • $K = 4$
  • $1 \leq W_1 < W_2 < \cdots < W_K \leq 10^6$
  • $1 \leq N \leq 250000$
  • $1 \leq A_i \leq K$
  • $1 \leq B_i \leq N$
  • All input values are integers.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N K
W_1 W_2 \ldots W_K
A_1 B_1
A_2 B_2
\vdots
A_N B_N

翻译中…

Output

翻译中…

Output the answer.

翻译中…

样例

Input #1
3 4
1 2 3 4
4 2
1 3
3 2
Output #1
15
If gems $1, 2, 3$ are put in boxes $3, 1, 2$, respectively, the sum of values is $4 \times \min(2, 3) + 1 \times \min(3, 1) + 3 \times \min(2, 2) = 15$, which is maximum.
Input #2
3 4
1 2 3 4
3 1
2 2
1 3
Output #2
10
Input #3
6 4
1 3 8 10
2 2
1 4
2 2
3 1
3 4
4 3
Output #3
86
Input #4
15 4
239277 249169 419371 744281
2 14
1 4
1 11
4 12
1 7
2 12
3 15
2 5
3 4
1 8
3 2
4 1
1 15
3 5
2 8
Output #4
39858078
题目信息
题号
agc073_d
时间限制
15 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。