#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,e) for (int i = s; i <= e; ++i)
#define rrep(i,s,e) for (int i = s; i >= e; --i)
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define all(a) a.begin(), a.end()
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
const int mx = 1e5;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m, k; cin >> n >> m >> k;
int a[n], b[m], s = 0;
rep (i,0,n-1) {
cin >> a[i];
if (a[i]<k) {
cout << "Impossible\n";
return 0;
}
s += a[i];
}
rep (i,0,m-1) cin >> b[i];
int dp[mx+1] = {}; //for some certain sum, what is the maximum number of different (chef, meal) pairs, if it is at least n*k and the sum is also more than the sum of ai (s), then we should have found an answer, lets see what is the minimum
rep (i,0,m-1)
rrep (j,mx,b[i])
dp[j] = max(dp[j], dp[j-b[i]] + min(b[i], n));
rep (i,s,mx) {
if (dp[i]>=n*k) {
cout << i-s << "\n";
return 0;
}
}
cout << "Impossible\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
588 KB |
Output is correct |
2 |
Incorrect |
1 ms |
700 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
588 KB |
Output is correct |
2 |
Incorrect |
1 ms |
700 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
21 ms |
588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
588 KB |
Output is correct |
2 |
Correct |
4 ms |
696 KB |
Output is correct |
3 |
Correct |
4 ms |
704 KB |
Output is correct |
4 |
Correct |
4 ms |
588 KB |
Output is correct |
5 |
Correct |
1 ms |
704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
588 KB |
Output is correct |
2 |
Incorrect |
1 ms |
700 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |