問題一覧 > 通常問題

No.1708 Quality of Contest

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 164
作問者 : chineristAC / テスター : 👑 hitonanode platinum
お気に入りにしたユーザー ProblemId : 5205 / 自分の提出
問題文最終更新日: 2021-10-15 00:31:38
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Show the original
yukicoder contest 318 (順位表) の他の問題:

Problem Statement

chinerist wants to hold a programming contest and has created $N$ problems. The problems are numbered from $1$ to $N$ in advance.

Each problem has $2$ values: its "quality", represented by an integer at least $0$, and its "genre", represented by an integer between $1$ and $M$, inclusive. The quality and genre of problem $i\ (1\le i\le N)$ are $A_i,\ B_i$.

These problems will be presented in some order, and the participants will solve them.

This contest has $K$ participants, and it is known that the $i\ (1\le i\le K)$-th participant solves $C_i$ problems, in order starting from the first problem presented.

The "satisfaction" of each participant is $($the sum of the qualities of the problems they solved$) + X \times ($the number of distinct genres among the problems they solved$)$.

Find the maximum possible value of the sum of the participants' satisfaction.

Input

$N$ $M$ $X$
$A_1$ $B_1$
$A_2$ $B_2$
$\vdots$
$A_N$ $B_N$
$K$
$C_1$ $C_2$ $\dots$ $C_K$

  • $1 \le N \le 2\times 10^5$
  • $1 \le M \le 2\times 10^5$
  • $0 \le X \le 10^7$
  • $0 \le A_i \le 10^7\ (1\le i \le N)$
  • $1 \le B_i \le M\ (1\le i \le N)$
  • $1 \le K \le 2\times 10^5$
  • $0 \le C_i \le N\ (1\le i \le K)$
  • All input values are integers.

Output

Output the answer.

Print a newline at the end.

Sample

Sample 1
Input
3 2 2
5 1
2 1
1 2
3
1 2 3
Output
29

Presenting the problems in the order $1,\ 3,\ 2$ maximizes the sum of satisfaction.

In this case, for example, participant $2$ solved problems with qualities $5,1$ and the genres are the $2$ kinds $1,2$, so their satisfaction is $(5+1)+2\times 2 = 10$.
Sample 2
Input
3 2 2
10 1
3 2
5 1
3
0 0 0
Output
0

Whatever the order of the problems, nobody solves even $1$ problem, so the satisfaction is $0$.

Sample 3
Input
15 4 5
6 3
40 1
20 3
5 2
16 3
10 4
21 1
6 2
30 2
5 3
47 1
1 2
5 1
19 4
38 4
6
5 7 1 3 11 12
Output
1168

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。