#P6228. [BalticOI 2019] 汤姆的餐厅 (Day2)
[BalticOI 2019] 汤姆的餐厅 (Day2)
Description
Tom's Kitchen is a very popular restaurant. One of the reasons for its popularity is that every dish is prepared by at least chefs. Today, there are dishes to be prepared. The preparation time of dish is hours.
Tom can hire chefs. Chef can work at most hours. Also, even if chef works fewer than hours, he will still be paid for hours. A chef may spend different amounts of time preparing different dishes, but each dish must be prepared by at least chefs, and the sum of the time they spend is exactly . When a chef prepares a dish, he always spends a positive integer number of hours.
Tom needs an optimal hiring plan to make the number of paid-but-not-worked hours (that is, the difference between the sum of the working time limits of all hired chefs and the total time needed to prepare all dishes) as small as possible.
Input Format
The first line contains three positive integers: .
The second line contains integers , and the third line contains integers .
Output Format
If there is no plan that can complete the preparation of all dishes, output Impossible. Otherwise, output one integer: the minimum number of paid-but-not-worked hours.
1 2 2
5
3 4
2
1 1 2
5
5
Impossible
3 3 3
3 3 2
3 3 3
Impossible
Hint
Sample Explanation 1
Tom needs to hire these two chefs to complete the preparation of all dishes. The total time to prepare all dishes is hours, but Tom needs to pay for hours, so the chefs get paid for hours without working.
Sample Explanation 2
Preparing one dish requires at least two chefs, but only one chef can be hired, so it is impossible to complete the preparation.
Sample Explanation 3
The third dish cannot be prepared by three chefs, because the preparation time of the third dish is only hours (this means that if three chefs prepare the third dish, at least one chef would spend hours preparing it, which is not allowed by the statement).
Subtasks
The scores and data scales of the subtasks are as follows:
- Subtask 1 (9 points): $1 \leq N, K \leq 300, 1 \leq M \leq 2, 1 \leq A_i, B_j \leq 300$;
- Subtask 2 (22 points): $1 \leq N, K \leq 300, 1 \leq M \leq 15, 1 \leq A_i, B_j \leq 300$;
- Subtask 3 (20 points): ;
- Subtask 4 (21 points): ;
- Subtask 5 (28 points): .
Translated by ChatGPT 5
京公网安备 11011102002149号