题目描述
Problem Description
Tom's Kitchen is a very popular restaurant, one of the reasons being that each dish is prepared by at least $K$ chefs. Today, there are $N$ dishes that need to be prepared, with the preparation time for the $i$-th dish being $A_i$ hours.
Tom can hire $M$ chefs, and chef $j$ can work for a maximum of $B_j$ hours. Additionally, even if chef $j$ works for less than $B_j$ hours, he will still be paid for $B_j$ hours. A chef can spend different amounts of time preparing different dishes, but each dish must be prepared by at least $K$ chefs, and the total time spent by these chefs must exactly equal $A_i$. When a chef prepares a dish, he always spends a positive integer number of hours.
Tom needs an optimal hiring plan to minimize the number of hours that chefs are paid for but do not work (i.e., the difference between the total maximum working hours of all hired chefs and the total time required to prepare all dishes).
Input Format
The first line contains three positive integers: $N, M, K$.
The second line contains $N$ integers $A_i$, and the third line contains $M$ integers $B_j$.
Output Format
If there is no plan that can complete the preparation of all dishes, output Impossible. Otherwise, output a single integer representing the minimum number of hours that chefs are paid for but do not work.
Sample Input and Output
Sample Input #1
1 2 2
5
3 4
Sample Output #1
2
Sample Input #2
1 1 2
5
5
Sample Output #2
Impossible
Sample Input #3
3 3 3
3 3 2
3 3 3
Sample Output #3
Impossible
Notes/Hints
Sample Explanation 1
Tom needs to hire both chefs to complete the preparation of all dishes. The total preparation time is $5$ hours, but Tom needs to pay for $3+4=7$ hours, meaning the chefs are paid for $2$ 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 for the third dish is only $2$ hours (which means if three chefs were to prepare it, at least one chef would have a preparation time of $0$ hours, which is not allowed).
Subtasks
The scores and data constraints for each subtask 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): $1 \leq N, M, A_i, B_j \leq 300, K=1$;
- Subtask 4 (21 points): $1 \leq N, M, K, A_i, B_j \leq 40$;
- Subtask 5 (28 points): $1 \leq N, M, K, A_i, B_j \leq 300$.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分