#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define FOR(i, l, r, d) for(int i=(l); i<=(r); i+=(d))
#define szof(x) ((int)(x).size())
#define vi vector<int>
#define pii pair<int, int>
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define mkp make_pair
const int INF = INT_MAX;
const int LNF = INF*INF;
const int MOD = 1000000007;
const int mod = 998244353;
const double eps = 1e-12;
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
const int MAX = 4810;
const int C = 40;
int n, m, lim; // meals, chefs, required chefs
int meal[MAX], chef[MAX], meal_sum;
bool dp[MAX][MAX]; // dp(chefs)[sum(min(n, chef[j]))][sum(chef[j])]
int res;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>m>>lim;
FOR(i, 1, n, 1){
cin>>meal[i];
meal_sum += meal[i];
}
FOR(i, 1, m, 1){
cin>>chef[i];
}
// meal[i] >= lim
FOR(i, 1, n, 1){
if(meal[i] < lim){
cout<<"Impossible"<<'\n';
return 0;
}
}
// dp
dp[0][0] = 1;
FOR(i, 1, m, 1){
for(int j = i*C; j >= 0; j--){
int jj = j + min(n, chef[i]);
for(int k = i*C; k >= 0; k--){
int kk = k + chef[i];
dp[jj][kk] |= dp[j][k];
}
}
/*
FOR(j, 0, 10, 1){
cerr<<"dp["<<j<<"] = ";
FOR(k, 0, 10, 1){
cerr<<dp[j][k]<<" ";
}
cerr<<endl;
}
cerr<<endl;
*/
}
res = INF;
FOR(j, n*lim, m*C, 1){
FOR(k, meal_sum, m*C, 1){
if(dp[j][k]) res = min(res, k - meal_sum);
}
}
if(res == INF) cout<<"Impossible"<<'\n';
else cout<<res<<'\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
465 ms |
43880 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
7944 KB |
Output is correct |
2 |
Correct |
23 ms |
7788 KB |
Output is correct |
3 |
Correct |
23 ms |
7900 KB |
Output is correct |
4 |
Correct |
22 ms |
7880 KB |
Output is correct |
5 |
Correct |
0 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |