No.2434 RAKUTAN de RAKUTAN
Problem Statement
Takahashi has decided to play a certain Game of Life. This game has a currency called "credits”, and credits can be obtained by stopping on specific squares. Takahashi does not want to repeat a year, so help him bring as many credits as possible to the goal.
This game consists of $N+1$ squares in total, from square $0$ to square $N$. Square $0$ is the start and square $N$ is the goal.
Initially, Takahashi is at the start with $0$ credits, and he heads for the goal from there.
Takahashi has $2$ ways of moving, as follows.
- Normal move: Move $1$ square forward. Example: square $2$ → square $3$
- Leap: Consume $1$ stamina and move $X$ squares forward. Example: when $X$ = $5$, square $5$ → square $10$
Furthermore, this game has the following $3$ types of squares.
- Lecture square: Nothing in particular happens. Every square that is neither a credit-earning square nor a credit-losing square is a lecture square.
- Credit-earning square: A credit has been dropped here. When he stops exactly on this square, the number of credits he holds changes by $+1$.
- Credit-losing square: When he stops exactly on this square, the number of credits he holds changes by $-1$. Note that the number of credits can become negative, so the answer can also be negative.
$1$ square is never both a credit-earning square and a credit-losing square.
See also the image at the end of the problem statement for how the game actually proceeds.
The numbers of credit-earning squares and credit-losing squares are given as $G$ , $B$, respectively, and their positions are given as $g_i$ , $b_i$, respectively. Also, square $0$ is a lecture square.
Initially, Takahashi is at the start with $0$ credits. Find the maximum number of credits Takahashi can bring to the goal.
The board and the progress of the game for Sample $1$ are shown below. On the route shown in the image, his stamina when he reaches the goal is $2$.
Constraints
- $1 \le N \le 10^9$
- $0 \le H \le 10^6$
- $2 \le X \le 5$
- $0 \le G \le \min(N, 1000)$
- $1 \le g_i \le N$
- $0 \le B \le \min(N-G, 1000)$
- $1 \le b_i \le N$
- $g_i \neq g_j $ ($1 \le i < j \le G$)
- $b_i \neq b_j $ ($1 \le i < j \le B$)
- $g_i \neq b_j $ ($1 \le i \le G$) ($1 \le j \le B$)
Input
$N\ H\ X$ $G$ $g_1\ g_2\ \dots\ g_G$ $B$ $b_1\ b_2\ \dots\ b_B$
Output
Output the maximum number of credits that can be brought to the goal square.
Sample
Sample 1
Input
12 3 5 5 2 3 5 10 11 4 4 6 7 9
Output
4
Moving through the squares as 0→1→2→3→4→5→10→11→12 is optimal. See also the image.
Sample 2
Input
8 2 3 2 2 5 2 6 8
Output
1
Moving through the squares as 0→1→2→3→4→5→8 is optimal.
Alternatively, 0→1→2→5→8 is also one of the optimal ways.
Sample 3
Input
30 7 3 2 3 7 23 2 4 5 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
Output
-7
The maximum number of credits that can be brought to the goal is -7.
The number of credits can be negative both along the way and in the final result.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
Astral__
noya2