問題一覧 > 通常問題

No.107 Monsters

レベル : / AI推定難易度 : 1000 / 実行時間制限 : 1ケース 5.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 232
作問者 : nmnmnmnmnmnmnm
お気に入りにしたユーザー ProblemId : 102 / 自分の提出
問題文最終更新日: 2026-06-25 02:09:00
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
yukicoder contest 67 (順位表) の他の問題:

Problem Statement

There are $N$ monsters.
There are $2$ kinds of monsters.
The $2$ kinds are bad monsters and good monsters.
You must fight bad monsters $1$ time per $1$ monster.
Fighting reduces your HP and raises your level by $1$.
When your level goes up by 1, your maximum HP increases by $100$.
If your HP drops to $0$ or below, it ends there.
Good monsters restore your HP only $1$ time per $1$ monster.
However, the restored HP never exceeds your maximum HP.

Your initial HP is $100$ and your initial maximum HP is also $100$.
You want to defeat all the bad monsters.
You also want to have as much HP as possible remaining at the end.
You can encounter the monsters in any order.
How much HP can you have left at the end?
If your HP drops to $0$ or below along the way no matter what you do, the answer is $0$.

Note that you cannot defeat good monsters.

Input

$N$
$D_1\ D_2\ ... D_{N}$

$N$ is the total number of monsters. $1\le N \le 16$. ($N$ is a positive integer.)
$D_i$ is the information about the $i$-th monster.
If $D_i$ is positive, it is a good monster that restores |$D_i$| HP.
If $D_i$ is negative, it is a bad monster, and defeating it costs |$D_i$| HP.
$-1600 \le Di < 0、0 < Di \le 1600$. ($D_i$ is an integer other than $0$.)

Output

Output the maximum possible HP at the end on one line.
If your HP drops to 0 or below along the way no matter what you do, output 0 on one line.
Do not forget the newline at the end.

Sample

Sample 1
Input
3
-90 50 50
Output
110

First, fight the 1st monster, which is a bad monster.
Your HP becomes 10 and your maximum HP becomes 200.
Have the 2 good monsters, the 2nd and 3rd, restore 50 HP each.
Your final HP is 110.
If you heal first, your HP does not rise above your maximum HP of 100.
In this case, if you fight last, your final HP is 10.

Sample 2
Input
4
-90 230 -120 120
Output
240

Fight the 1st monster, which is a bad monster.
Your HP becomes 10 and your maximum HP becomes 200.
Have the 4th monster, which is a good monster, heal you.
Your HP becomes 130.
Fight the 3rd monster, which is a bad monster.
Your HP becomes 10 and your maximum HP becomes 300.
Have the 2nd monster, which is a good monster, heal you.
Your HP becomes 240.

Sample 3
Input
4
-10 -300 100 100
Output
0

Fighting the 1st monster, which is a bad monster, reduces your HP to 90 and makes your maximum HP 200.
The 3rd and 4th monsters, which are good monsters, can heal you up to 200 HP.
However, no matter what you do, your HP drops to 0 or below when you fight the 2nd monster, which is a bad monster.

Sample 4
Input
4
-40 -60 210 -110
Output
50

Fight the 2nd monster, which is a bad monster.
Your HP becomes 40 and your maximum HP becomes 200.
Have the 3rd monster, which is a good monster, heal you.
Since HP cannot exceed the maximum HP, your HP becomes 200.
Fight the 1st and 4th monsters, which are bad monsters.
Your HP becomes 50.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。