시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB43262559.524%

문제

Tom’s Kitchen is a very popular restaurant. One of the reasons for its popularity is that every single meal is prepared by at least K different chefs. Today, there are N meals to be prepared, with meal i needing Ai hours of work.

There are M chefs which Tom can hire to prepare all the meals but the chef j will work at most Bj hours. Additionally, even when he works less, he still wants to be paid for the full Bj hours. A chef can work on several meals for different amounts of time, but any meal will be properly prepared only if at least K chefs take part in preparing it and the total time they spend is exactly Ai. When a chef takes part in preparing a meal, he always works on it some positive integer number of hours.

Tom needs help in choosing the optimal subset of chefs such that the sum of hours where the chefs are getting paid without working is minimized.

입력

The first line contains the integers N, M, and K.

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

출력

The only line should contain the number of hours the chefs spend not working but still getting paid when Tom chooses the optimal subset to hire. If there is no way to prepare all the N meals according to the rules described above, output “Impossible”.

서브태스크

번호배점제한
19

1 ≤ N, K ≤ 300, 1 ≤ M ≤ 2, 1 ≤ Ai, Bj ≤ 300.

222

1 ≤ N, K ≤ 300, 1 ≤ M ≤ 15, 1 ≤ Ai, Bj ≤ 300.

320

1 ≤ N, M, Ai, Bj ≤ 300, K = 1.

421

1 ≤ N, M, K, Ai, Bj ≤ 40.

528

1 ≤ N, M, K, Ai, Bj ≤ 300.

예제 입력 1

1 2 2
5
3 4

예제 출력 1

2

Here Tom needs two chefs to work on the meal, so he must hire both that are available. Then it does not matter how they divide the work, as they end up working a total of 5 hours, but getting paid for 3 + 4 = 7 hours, and thus getting paid for 2 extra hours.

예제 입력 2

1 1 2
5
5

예제 출력 2

Impossible

Here Tom needs two chefs to work on the meal, but only one is available.

예제 입력 3

3 3 3
3 3 2
3 3 3

예제 출력 3

Impossible

Here meal 3 can’t be prepared by three chefs, as each would have to work for at least an hour, but the meal takes only 2 hours to prepare.

채점 및 기타 정보

  • 예제는 채점하지 않는다.