#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
const int M = 100005;
const ll inf = 1e9;
const ll mod = 998244353;
const double pi = acos(-1);
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
int n, m, k, a[M], b[M], sum, tot, ans = inf, dp[M];
int main()
{
scanf("%d%d%d", &n, &m, &k);
for(int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
sum += a[i];
if(a[i] < k) printf("Impossible\n"), exit(0);
}
for(int i = 1; i <= m; ++i) scanf("%d", &b[i]), tot += b[i];
if(sum > tot) printf("Impossible\n"), exit(0);
for(int i = 1; i <= m; ++i){
for(int j = M - b[i] - 1; j >= 0; --j) if(j == 0 || dp[j]) {
dp[j + b[i]] = max(dp[j + b[i]], dp[j] + min(n, b[i]));
}
}
for(int i = sum; i < M; ++i) if(dp[i] >= n * k) printf("%d\n", i - sum), exit(0);
printf("Impossible\n");
return 0;
}
Compilation message
kitchen.cpp: In function 'int main()':
kitchen.cpp:19:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
19 | scanf("%d%d%d", &n, &m, &k);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
kitchen.cpp:21:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
21 | scanf("%d", &a[i]);
| ~~~~~^~~~~~~~~~~~~~
kitchen.cpp:25:35: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
25 | for(int i = 1; i <= m; ++i) scanf("%d", &b[i]), tot += b[i];
| ~~~~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
2 ms |
204 KB |
Output is correct |
10 |
Correct |
2 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
2 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
452 KB |
Output is correct |
2 |
Correct |
18 ms |
416 KB |
Output is correct |
3 |
Correct |
31 ms |
400 KB |
Output is correct |
4 |
Correct |
28 ms |
516 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
18 ms |
428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
204 KB |
Output is correct |
2 |
Correct |
3 ms |
204 KB |
Output is correct |
3 |
Correct |
3 ms |
204 KB |
Output is correct |
4 |
Correct |
3 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
2 ms |
204 KB |
Output is correct |
10 |
Correct |
2 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
2 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
21 ms |
452 KB |
Output is correct |
15 |
Correct |
18 ms |
416 KB |
Output is correct |
16 |
Correct |
31 ms |
400 KB |
Output is correct |
17 |
Correct |
28 ms |
516 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
18 ms |
428 KB |
Output is correct |
20 |
Correct |
4 ms |
204 KB |
Output is correct |
21 |
Correct |
3 ms |
204 KB |
Output is correct |
22 |
Correct |
3 ms |
204 KB |
Output is correct |
23 |
Correct |
3 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
16 ms |
424 KB |
Output is correct |
26 |
Correct |
20 ms |
540 KB |
Output is correct |
27 |
Correct |
13 ms |
424 KB |
Output is correct |
28 |
Correct |
21 ms |
468 KB |
Output is correct |
29 |
Correct |
22 ms |
544 KB |
Output is correct |
30 |
Correct |
28 ms |
612 KB |
Output is correct |