#include <iostream>
using namespace std;
const long long maxN = 305, inf = 1e15;
long long barr[maxN], dp[maxN][555555];
int main(){
long long n, m, k;
cin >> n >> m >> k;
long long total = 0, total1 = 0;
for (int i = 0; i < n; i++){
int a;
cin >> a;
if (a < k){
cout << "Impossible" << endl;
return 0;
}
total += a;
}
for (int i = 0; i < m; i++) cin >> barr[i], total1 += barr[i];
for (int i = 0; i < m; i++){
for (int j = 0; j <= total1; j++) dp[i][j] = -inf;
}
dp[0][barr[0]] = min(n, barr[0]);
for (int i = 1; i < m; i++){
for (int j = 0; j <= total1; j++){
dp[i][j] = dp[i-1][j];
if (barr[i] <= j){
if (dp[i-1][j-barr[i]] == -inf) continue;
dp[i][j] = max(dp[i][j], dp[i-1][j-barr[i]] + min(n, barr[i]));
}
}
}
bool pos = 0;
long long ans;
for (int i = total; i <= total1; i++){
if (dp[m-1][i] >= n*k){
pos = 1;
ans = i;
break;
}
}
if (!pos) cout << "Impossible" << endl;
else cout << ans-total << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
79 ms |
137020 KB |
Output is correct |
2 |
Correct |
48 ms |
102548 KB |
Output is correct |
3 |
Correct |
54 ms |
115400 KB |
Output is correct |
4 |
Correct |
102 ms |
196516 KB |
Output is correct |
5 |
Correct |
125 ms |
196768 KB |
Output is correct |
6 |
Correct |
46 ms |
83408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
852 KB |
Output is correct |
3 |
Correct |
1 ms |
952 KB |
Output is correct |
4 |
Correct |
1 ms |
1080 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |