#abc270d. D - Stones

D - Stones

Score : 400400 points

问题描述

Takahashi 和 Aoki 将通过一个序列 (A1,,AK)(A_1, \ldots, A_K) 进行一场取石子游戏。

初始时,有一堆包含 NN 个石子。两位玩家将轮流执行以下操作,由 Takahashi 先手执行:

  • 选择一个不超过当前堆中石子数量的 AiA_i,然后从堆中移除 AiA_i 个石子。

当堆中没有石子时,游戏结束。

如果两名玩家都试图在游戏结束前最大化自己所移除的石子总数,那么 Takahashi 最终会移除多少个石子呢?

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

Takahashi and Aoki will play a game of taking stones using a sequence (A1,,AK)(A_1, \ldots, A_K).

There is a pile that initially contains NN stones. The two players will alternately perform the following operation, with Takahashi going first.

  • Choose an AiA_i that is at most the current number of stones in the pile. Remove AiA_i stones from the pile.

The game ends when the pile has no stones.

If both players attempt to maximize the total number of stones they remove before the end of the game, how many stones will Takahashi remove?

Constraints

  • 1N1041 \leq N \leq 10^4
  • 1K1001 \leq K \leq 100
  • 1=A1<A2<<AKN1 = A_1 < A_2 < \ldots < A_K \leq N
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

NN KK

A1A_1 A2A_2 \ldots AKA_K

Output

Print the answer.

Sample Input 1

10 2
1 4

Sample Output 1

5

Below is one possible progression of the game.

  • Takahashi removes 44 stones from the pile.
  • Aoki removes 44 stones from the pile.
  • Takahashi removes 11 stone from the pile.
  • Aoki removes 11 stone from the pile.

In this case, Takahashi removes 55 stones. There is no way for him to remove 66 or more stones, so this is the maximum.

Below is another possible progression of the game where Takahashi removes 55 stones.

  • Takahashi removes 11 stone from the pile.
  • Aoki removes 44 stones from the pile.
  • Takahashi removes 44 stones from the pile.
  • Aoki removes 11 stone from the pile.

Sample Input 2

11 4
1 2 3 6

Sample Output 2

8

Below is one possible progression of the game.

  • Takahashi removes 66 stones.
  • Aoki removes 33 stones.
  • Takahashi removes 22 stones.

In this case, Takahashi removes 88 stones. There is no way for him to remove 99 or more stones, so this is the maximum.

Sample Input 3

10000 10
1 2 4 8 16 32 64 128 256 512

Sample Output 3

5136

update @ 2024/3/10 11:23:25