P9339 [JOISC 2023] Cookies (Day3)
题目描述
莉婕喜欢做饼干。她制作了 $N$ 种饼干。第 $i$ 种饼干有 $A_i$ 个。为了出售她制作的饼干,她将它们装入盒子中。但是,应该满足以下条件。
+ 对于每个盒子,其中的饼干种类应不同。
+ 对于每个盒子,其中的饼干数量应等于以下 $M$ 个数字之一:$B_1,B_2,⋯ ,B_M$。
编写一个程序,给出莉婕制作的饼干信息和将饼干装箱的条件,确定是否可能将所有饼干包装到盒子中。此外,如果可以将所有饼干包装在盒子中,则您的程序应输出最少的盒子数量。
输入格式
无
输出格式
无
说明/提示
**【样例解释 #1】**
In this sample input, it is possible to pack the $7$ cookies into $3$ boxes so that the conditions are satisfied as follows.
- Pack cookies of types $1, 7$ into the first box. Pack one cookie for each type.
- Pack cookies of types $2, 6$ into the second box. Pack one cookie for each type.
- Pack cookies of types $3, 4, 5$ into the third box. Pack one cookie for each type.
Your program is judged as correct if it outputs the above way to pack the cookies because it is impossible to pack the $7$ cookies into less than or equal to $2$ boxes so that the conditions are satisfied. There are other ways to pack the cookies which are judged as correct.
This sample input satisfies the constraints of Subtasks 1, 3, 4, 5, 6.
**【样例解释 #2】**
In this sample input, it is impossible to pack the $15$ cookies into boxes so that the conditions are satisfied.
Therefore, output $-1$.
This sample input satisfies the constraints of Subtasks 2, 3, 4, 5, 6.
**【样例解释 #3】**
This sample input satisfies the constraints of Subtasks 4, 5, 6.
**【数据范围】**
对于所有测试数据,满足 $1 \leq N \leq 15 000$,$A _ i \geq 1$($1 \leq i \leq n$),$A _ 1 + A _ 2 + \cdots + A _ N \leq 15 000$,$1 \leq M \leq N$,$1 \leq B _ j \leq N$($1 \leq j \leq M$),$B _ j < B _ {j + 1}$($1 \leq j \leq M - 1$),保证所有输入均为整数。
| **子任务编号** | **分值** | **限制** |
| :----------: | :----------: | :----------: |
| $1$ | $6$ | $N \leq 500$,$A _ i = 1$($1 \leq i \leq N$) |
| $2$ | $7$ | $N \leq 500$,$M = 1$ |
| $3$ | $12$ | $A _ 1 + A _ 2 + \cdots + A _ N \leq 15$ |
| $4$ | $45$ | $A _ 1 + A _ 2 + \cdots + A _ N \leq 500$ |
| $5$ | $15$ | $A _ 1 + A _ 2 + \cdots + A _ N \leq 3000$ |
| $6$ | $15$ | 没有额外的限制 |