#P9744. 「KDOI-06-S」消除序列
「KDOI-06-S」消除序列
Problem Description
Little M has a sequence of length . Initially, all elements are .
You have types of operations on this sequence:
- Choose an index (), and set all to . The cost of this operation is .
- Choose an index (), and set to . The cost of this operation is .
- Choose an index (), and set to . The cost of this operation is .
Now there are queries. In each query, you are given a set . You want to perform some operations (possibly operations) so that: the elements whose indices belong to this set have value , and all other positions have value . Formally, for any , if then , otherwise . You also need to minimize the total cost of all operations in this query.
Note that the queries are independent. That is, after each query ends, the sequence returns to the initial state, where all elements become again.
Input Format
Read input from standard input.
The first line contains a positive integer , denoting the length of the sequence .
The second line contains non-negative integers , denoting the cost of the first type of operation.
The third line contains non-negative integers , denoting the cost of the second type of operation.
The fourth line contains non-negative integers , denoting the cost of the third type of operation.
The fifth line contains a positive integer , denoting the number of queries.
In the following lines, the -th line contains:
- A leading non-negative integer , denoting the size of set in the -th query.
- Then positive integers , in order, denoting each element in set . It is guaranteed that for any , .
Output Format
Write to standard output.
Output lines. The -th line contains a non-negative integer, denoting the minimum total cost of operations in the -th query.
5
1 13 6 0 6
2 4 1 0 5
3 4 1 2 1
7
1 4
2 1 5
1 4
2 2 3
5 1 2 3 4 5
1 5
2 3 4
7
3
7
6
0
0
8
7
10 1 6 9 4 2 4
0 5 2 3 0 1 4
4 1 4 1 5 3 5
6
3 1 3 6
2 2 6
4 3 4 5 7
1 4
2 3 7
3 3 5 6
12
8
2
5
5
8
10
6 10 7 2 8 4 6 4 8 7
4 0 6 7 8 4 8 2 10 5
4 10 6 1 4 7 5 3 8 7
1
0
7
Hint
[Sample Explanation #1]
For the first query, you can perform the following operations in order:
- Perform operation at . After that, the sequence becomes , with cost .
- Perform operation at . After that, the sequence becomes , with cost .
- Perform operation at . After that, the sequence becomes , with cost .
So the total cost is . It can be proven that there is no smaller total cost.
[Sample Explanation #3]
For the only query in this sample, you can choose to perform operation at , with total cost .
[Sample #4]
See reserve/reserve4.in and reserve/reserve4.ans under the contestant directory.
[Sample #5]
See reserve/reserve5.in and reserve/reserve5.ans under the contestant directory.
This sample satisfies the constraints of test points .
[Sample #6]
See reserve/reserve6.in and reserve/reserve6.ans under the contestant directory.
This sample satisfies the constraints of test points .
[Sample #7]
See reserve/reserve7.in and reserve/reserve7.ans under the contestant directory.
This sample satisfies the constraints of test point .
[Sample #8]
See reserve/reserve8.in and reserve/reserve8.ans under the contestant directory.
This sample satisfies the constraints of test points .
[Constraints]
Let be the sum of all over all queries within one test case.
It is guaranteed for all data that: , , , , , .
| Test Point ID | Special Property | |||
|---|---|---|---|---|
| No | ||||
| Yes | ||||
| No | ||||
| Yes | ||||
| No | ||||
Special property: for any , it is guaranteed that .
[Hint]
The input and output sizes of this problem are large, so please use an appropriate I/O method.
Translated by ChatGPT 5