#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m, k; cin >> n >> m >> k;
vector<int> A(n), B(m);
int s1 = 0, s2 = 0;
for(int &x: A){
cin >> x, s1+=x;
if(x < k){
cout << "Impossible\n";
exit(0);
}
}
for(int &x: B) cin >> x, s2+=x;
vector<vector<int>> dp(m, vector<int>(s2+1, -1e9));
for(int i = 0; i < m; i++) dp[i][0] = 0;
dp[m-1][B[m-1]] = 0;
for(int i = m-2; i >= 0; i--) for(int j = s2; j >= 0; j--){
dp[i][j] = dp[i+1][j];
if(j-B[i] >= 0){
dp[i][j] = max(dp[i][j], dp[i+1][j-B[i]] + min(B[i], n));
}
}
for(int i = s1; i <= s2; i++){
if(dp[0][i] >= n*k){
cout << i-s1 << "\n";
exit(0);
}
}
cout << "Impossible\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
68556 KB |
Output is correct |
2 |
Correct |
43 ms |
51144 KB |
Output is correct |
3 |
Correct |
48 ms |
56908 KB |
Output is correct |
4 |
Correct |
80 ms |
97988 KB |
Output is correct |
5 |
Correct |
83 ms |
98252 KB |
Output is correct |
6 |
Correct |
34 ms |
41292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |