#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 10000000
int main(){
ll n, m, k, su = 0;
cin>>n>>m>>k;
if (m < k){
cout<<"Impossible";
return 0;
}
vector<ll> a(n + 1), b(m + 1);
for (int i = 0; i< n; i++){
cin>>a[i + 1];
su += a[i + 1];
if (a[i + 1] < k){
cout<<"Impossible";
return 0;
}
}
for (int i = 0; i < m; i++){
cin>>b[i + 1];
}
vector<vector<vector<ll>>> dp(m + 1, vector<vector<ll>>(m + 1, vector<ll>(m + 1, 0)));
for (int i = 1; i <= m; i++){
for (int j = 1; j <= i; j++){
for (int l = i * k; l <= k * n; l++){
if (a[j] >= l){
dp[i][j][l] = max(dp[i - 1][j - 1][0] + a[j] - l, dp[i - 1][j][l]);
}
else if (a[j] >= k){
dp[i][j][l] = max(dp[i - 1][j - 1][l - k] + max(a[j] - k, 0ll), dp[i - 1][j][l]);
}
else{
dp[i][j][l] = max(dp[i - 1][j - 1][l - a[j]], dp[i - 1][j][l]);
}
}
}
}
ll ans = m + 1;
for (ll i = k; i <= m; i++){
ll val = max(ans, dp[m][i][k * n]);
if (val >= su - k * i){
ans = min(ans, i);
}
}
cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2256 ms |
262144 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
1624 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |