#include <bits/stdc++.h>
using namespace std;
int n,m,k,dp[90005],a[305],b[305],sum;
void impossible(){
cout << "Impossible\n";
exit(0);
}
int main() {
ios::sync_with_stdio(false); cin.tie(0);
cin >> n >> m >> k;
if (m < k) impossible();
for (int i=1;i<=n;i++){
cin >> a[i];
sum+=a[i];
if (a[i] < k) impossible();
}
for (int i=1;i<=90000;i++){
dp[i]=-1;
}
for (int i=1;i<=m;i++){
cin >> b[i];
for (int j=90000;j>=b[i];j--){
if (dp[j] == -1 && dp[j-b[i]] >= 0)
dp[j]=dp[j-b[i]]+min(b[i],n);
else
if (dp[j] > 0 && dp[j-b[i]] >= 0)
dp[j]=max(dp[j],dp[j-b[i]]+min(b[i],n));
}
}
for (int i=sum;i<=90000;i++){
if (dp[i] >= n*k){
cout << i-sum << "\n";
return 0;
}
}
impossible();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
676 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
676 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
2 ms |
596 KB |
Output is correct |
11 |
Correct |
2 ms |
596 KB |
Output is correct |
12 |
Correct |
2 ms |
588 KB |
Output is correct |
13 |
Correct |
2 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
684 KB |
Output is correct |
2 |
Correct |
16 ms |
684 KB |
Output is correct |
3 |
Correct |
25 ms |
596 KB |
Output is correct |
4 |
Correct |
27 ms |
680 KB |
Output is correct |
5 |
Correct |
30 ms |
680 KB |
Output is correct |
6 |
Correct |
15 ms |
588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
580 KB |
Output is correct |
2 |
Correct |
4 ms |
588 KB |
Output is correct |
3 |
Correct |
4 ms |
680 KB |
Output is correct |
4 |
Correct |
5 ms |
588 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
676 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
2 ms |
596 KB |
Output is correct |
11 |
Correct |
2 ms |
596 KB |
Output is correct |
12 |
Correct |
2 ms |
588 KB |
Output is correct |
13 |
Correct |
2 ms |
596 KB |
Output is correct |
14 |
Correct |
20 ms |
684 KB |
Output is correct |
15 |
Correct |
16 ms |
684 KB |
Output is correct |
16 |
Correct |
25 ms |
596 KB |
Output is correct |
17 |
Correct |
27 ms |
680 KB |
Output is correct |
18 |
Correct |
30 ms |
680 KB |
Output is correct |
19 |
Correct |
15 ms |
588 KB |
Output is correct |
20 |
Correct |
4 ms |
580 KB |
Output is correct |
21 |
Correct |
4 ms |
588 KB |
Output is correct |
22 |
Correct |
4 ms |
680 KB |
Output is correct |
23 |
Correct |
5 ms |
588 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
15 ms |
680 KB |
Output is correct |
26 |
Correct |
19 ms |
592 KB |
Output is correct |
27 |
Correct |
15 ms |
596 KB |
Output is correct |
28 |
Correct |
23 ms |
588 KB |
Output is correct |
29 |
Correct |
24 ms |
596 KB |
Output is correct |
30 |
Correct |
31 ms |
584 KB |
Output is correct |