#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 K K chefs. Today, there are N N dishes to be prepared. The preparation time of dish i i is Ai A_i hours.

Tom can hire M M chefs. Chef j j can work at most Bj B_j hours. Also, even if chef j j works fewer than Bj B_j hours, he will still be paid for Bj B_j hours. A chef may spend different amounts of time preparing different dishes, but each dish must be prepared by at least K K chefs, and the sum of the time they spend is exactly Ai A_i . 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: N,M,K N, M, K .

The second line contains N N integers Ai A_i , and the third line contains M M integers Bj B_j .

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 5 5 hours, but Tom needs to pay for 3+4=7 3+4=7 hours, so the chefs get paid for 2 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 of the third dish is only 2 2 hours (this means that if three chefs prepare the third dish, at least one chef would spend 0 0 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): 1N,M,Ai,Bj300,K=1 1 \leq N, M, A_i, B_j \leq 300, K=1 ;
  • Subtask 4 (21 points): 1N,M,K,Ai,Bj40 1 \leq N, M, K, A_i, B_j \leq 40 ;
  • Subtask 5 (28 points): 1N,M,K,Ai,Bj300 1 \leq N, M, K, A_i, B_j \leq 300 .

Translated by ChatGPT 5