#P1049. [NOIP 2001 普及组] 装箱问题

    ID: 49 远端评测题 1000ms 125MiB 尝试: 3 已通过: 2 难度: 3 上传者: 标签>动态规划,dp2001递归NOIp 普及组背包

[NOIP 2001 普及组] 装箱问题

Description

There is a box with capacity VV, and there are nn items. Each item has a volume.

Now choose any number of items from the nn items (possibly none) to put into the box, so that the remaining space in the box is minimized. Output this minimum value.

Input Format

The first line contains a single integer VV, indicating the capacity of the box.

The second line contains a single integer nn, indicating the total number of items.

The next nn lines each contain a positive integer, where the ii-th line gives the volume of the ii-th item.

Output Format

Output a single integer in one line, indicating the minimal remaining space in the box.

24
6
8
3
12
7
9
7

0

Hint

Constraints:

  • 0<n300 < n \le 30.
  • 1V200001 \le V \le 20000.

Source: NOIP 2001 Junior, Problem 4.

Translated by ChatGPT 5