| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 3 초 | 2048 MB | 31 | 12 | 11 | 40.741% |
JOI-kun lives in the country of IOI, which is famous for its large lake. Today, a stamp rally competition will be held around the lake.
Around the lake, there are $2N$ evenly spaced locations, numbered from $1$ to $2N$ in a clockwise manner. Additionally, there are $2N$ one-way roads connecting adjacent locations. Road $i$ ($1 ≤ i ≤ 2N - 1$) goes from location $i$ to location $i+1$, and road $2N$ goes from location $2N$ to location $1$. At the midpoint of each road, there is a stamp station.
There are $N$ colors of stamps numbered from $1$ to $N$. The color of the stamp that can be obtained at the stamp station on road $i$ ($1 ≤ i ≤ 2N$) is given by $A_i$. For each color $j$ ($1 ≤ j ≤ N$), there are exactly $2$ stamp stations where the stamp of that color can be obtained.
JOI-kun, equipped with many stamp cards, participates in the stamp rally competition. Each stamp card has two spaces, left and right, where stamps can be pressed. At most one stamp can be placed in each space. Initially, all stamp cards are blank.
The process of the stamp rally competition for JOI-kun is as follows:
JOI-kun wants to collect many distinct types of stamp cards that are stamped on both spaces. Let stamped card $(a, b)$ be a stamp card with color $a$ stamped on the left and color $b$ stamped on the right. Two stamped cards $(a_1, b_1)$ and $(a_2, b_2)$ are considered the same type if and only if $a_1 = a_2$ and $b_1 = b_2$. Since there are $N$ colors of stamps, there are a total of $N^2$ possible types of stamped cards.
You need to answer $Q$ queries to help JOI-kun. The $q$-th query ($1 ≤ q ≤ Q$) asks the following:
Given the information about stamp colors, participation costs, swap costs, and queries, write a program to answer JOI-kun’s $Q$ queries.
Read the following data from the standard input.
$N$ $X$
$A_1$ $A_2$ $\cdots$ $A_{2N}$
$C_1$ $C_2$ $\cdots$ $C_{2N}$
$Q$
$K_1$
$K_2$
$\vdots$
$K_Q$
Write $Q$ lines to the standard output, where the $q$-th line ($1 ≤ q ≤ Q$) contains the minimum total cost required to collect at least $K_q$ types of stamped cards.
| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 5 | $N ≤ 4$. |
| 2 | 20 | $N ≤ 5000$, $Q = 1$, $K_1 = N^2$. |
| 3 | 20 | $N ≤ 5000$, $Q = 1$. |
| 4 | 19 | $N ≤ 5000$. |
| 5 | 21 | $Q = 1$. |
| 6 | 15 | No additional constraints. |
3 2 1 2 2 3 1 3 6 1 4 5 4 7 2 8 9
3 4
Consider the case where JOI-kun selects location $2$ as the starting point and instructs the exchange of the stamp stations installed on road $3$ and road $4$.
In this case,
Since it is impossible to obtain $8$ or more types of stamped cards with a cost of $2$ or less, the first line of the output should be $3$.
Additionally, if JOI-kun selects location $3$ as the starting point and does not instruct any stamp station exchange, he can obtain $9$ types of stamped cards.
In this case, the total cost paid by JOI-kun is $C_3 + X \times 0 = 4$. Since it is impossible to obtain $9$ or more types of stamped cards with a cost of $3$ or less, the second line of the output should be $4$.
This input example satisfies the constraints of subtasks 1, 4, 6.
8 1 1 2 6 1 6 3 8 4 5 5 3 4 7 2 7 8 4 5 3 6 2 9 1 4 6 3 8 5 2 9 4 7 1 64
7
Consider the case where JOI-kun chooses location $10$ as the starting point and instructs the stamp station exchanges in the following order:
In this case, JOI-kun can obtain $64$ types of stamped cards, and the total cost paid is $C_{10} + X \times 4 = 7$.
This input example satisfies the constraints of subtasks 2, 3, 4, 5, 6.
9 4 4 3 5 3 8 1 5 8 1 7 6 2 4 9 6 9 2 7 12 9 4 8 7 1 20 5 8 7 4 13 5 9 10 3 7 8 6 39 81 73 79 64 52
1 18 3 10 1 1
This input example satisfies the constraints of subtasks 4, 6.