#P7842. 「C.E.L.U-03」探险者笔记 III

「C.E.L.U-03」探险者笔记 III

Description

The remade Explorer's Notes consists of nn levels. Each level has a difficulty bib_i. There are also mm achievements. The ii-th achievement requires you to complete exactly sumisum_i levels, and they must be exactly ai1,ai2,...,aisumia_{i_1}, a_{i_2}, ..., a_{i_{sum_i}}. Completing the ii-th achievement gives you a score of viv_i.
If you push levels for a long time without getting any achievement, Xiao Soup will feel tired. Also, achievements must be unlocked in a certain order. Therefore, if the last obtained achievement is the ii-th one, then the condition to obtain the jj-th achievement next is: i<ji < j and $w+\sum\limits_{k=1}^{sum_i} b_{a_{i_k}} \ge \sum\limits_{k=1}^{sum_j} b_{a_{j_k}}$, where ww is a given constant.
There are no restrictions for obtaining the first achievement. Find the maximum total score he can get.

Input Format

The first line contains three numbers n,m,wn, m, w.
The second line contains nn numbers bib_i.
The next mm lines describe the achievements. In the ii-th line, the first two numbers are vi,sumiv_i, sum_i, followed by sumisum_i numbers ai1,ai2,...,aisumia_{i_1}, a_{i_2}, ..., a_{i_{sum_i}}.

Output Format

Only one number, the answer.

3 3 1
1 1 2
2 1 1
2 2 1 2
3 2 1 3
4
4 6 2
1 1 3 2
3 3 1 2 3
2 2 2 3
3 3 2 3 4
2 2 1 3
4 3 1 3 4
6 4 1 2 3 4
12

Hint

Sample Explanation

Sample Explanation 1
Complete achievements 1,21, 2 in order.

Sample Explanation 2
Complete achievements 4,5,64, 5, 6 in order. Note that the restriction between achievements only takes effect between two adjacent obtained achievements.

Constraints

Testdata ID nn \le mm \le
11 99 10310^3
22 1818
363 \sim 6 99 10510^5
7107 \sim 10 1818

For 100%100\% of the testdata: 1n181 \le n \le 18, 1m1051 \le m \le 10^5, 1sumi181 \le sum_i \le 18, 1w,bi,vi1031 \le w, b_i, v_i \le 10^3, 1ain1 \le a_i \le n.

Translated by ChatGPT 5