#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define F first
#define S second
using namespace std;
const int N = 2e5 + 10;
const int mod = 1e9 + 7;
const int inf = 1e18;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,m,k;
cin >> n >> m >> k;
vector<int>a(n + 1);
int sa = 0;
for(int i = 1; i <= n; i++) {
cin >> a[i];
sa += a[i];
if(a[i] < k) {
cout << "Impossible";
return 0;
}
}
vector<int>b(m + 1);
int sum = 0;
for(int i = 1; i <= m; i++) {
cin >> b[i];
sum += b[i];
}
vector<int>dp(sum + 1,-inf);
dp[0] = 0;
for(int i = 1; i <= m; i++) {
vector<int>ndp = dp;
for(int j = b[i]; j <= sum; j++) {
ndp[j] = max(ndp[j],dp[j - b[i]] + min(b[i],n));
}
dp = ndp;
}
int res = -1;
for(int i = sum; i >= sa; i--) {
if(dp[i] >= n * k) res = i - sa;
}
if(res == -1) {
cout << "Impossible";
}else {
cout << res;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
1360 KB |
Output is correct |
2 |
Correct |
21 ms |
1172 KB |
Output is correct |
3 |
Correct |
28 ms |
1280 KB |
Output is correct |
4 |
Correct |
38 ms |
1736 KB |
Output is correct |
5 |
Correct |
44 ms |
1712 KB |
Output is correct |
6 |
Correct |
16 ms |
1224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
28 ms |
1360 KB |
Output is correct |
15 |
Correct |
21 ms |
1172 KB |
Output is correct |
16 |
Correct |
28 ms |
1280 KB |
Output is correct |
17 |
Correct |
38 ms |
1736 KB |
Output is correct |
18 |
Correct |
44 ms |
1712 KB |
Output is correct |
19 |
Correct |
16 ms |
1224 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
21 ms |
1272 KB |
Output is correct |
26 |
Correct |
29 ms |
1368 KB |
Output is correct |
27 |
Correct |
7 ms |
880 KB |
Output is correct |
28 |
Correct |
20 ms |
1204 KB |
Output is correct |
29 |
Correct |
28 ms |
1360 KB |
Output is correct |
30 |
Correct |
42 ms |
1728 KB |
Output is correct |