問題一覧 > 通常問題

No.2434 RAKUTAN de RAKUTAN

レベル : / AI推定難易度 : 1700 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 28
作問者 : Astral__ / テスター : shobonvip noya2 👑 potato167 tassei903 ponjuice
お気に入りにしたユーザー ProblemId : 9995 / 自分の提出
問題文最終更新日: 2023-08-18 19:48:19
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. Back to the original
traP 作問ハッカソンコンテスト 001 (順位表) の他の問題:

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.

  1. Normal move: Move $1$ square forward. Example: square $2$ → square $3$
  2. Leap: Consume $1$ stamina and move $X$ squares forward. Example: when $X$ = $5$, square $5$ → square $10$
Takahashi's initial stamina and the leap distance are given as $H$ and $X$, respectively. Normal moves can be chosen any number of times, but a leap can be chosen only when his stamina is $1$ or more. Also, a leap cannot be made if it would take him beyond square $N$.

Furthermore, this game has the following $3$ types of squares.
  1. Lecture square: Nothing in particular happens. Every square that is neither a credit-earning square nor a credit-losing square is a lecture square.
  2. 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$.
  3. 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$)
All inputs are integers.

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もしくは右上の雲マークをクリックしてアカウントを作成してください。