#include <bits/stdc++.h>
using namespace std;
#define debug(x) {cout << #x << ": "; for (auto it : x) cout << it << " ";cout << enl;}
#define fast ios::sync_with_stdio(0);cin.tie(0);
typedef long long ll;
#define f first
#define s second
#define MOD 998244353
#define LOGN 20
#define MAXN 305
int dp[MAXN][90005];
vector<int> meal, chef;
int main() {
fast
int N, M, K;
cin >> N >> M >> K;
meal = vector<int>(N+1);
chef = vector<int>(M+1);
int sum = 0;
for (int i = 1; i <= N; i++) {
cin >> meal[i];
sum += meal[i];
if (meal[i] < K) {
cout << "Impossible\n";
return 0;
}
}
for (int i = 1; i <= M; i++)
cin >> chef[i];
for (int i = 0; i <= M; i++) {
for (int total = 0; total <= 90000; total++)
dp[i][total] = -1e8;
}
dp[0][0] = 0;
for (int i = 1; i <= M; i++) {
for (int total = 0; total <= 90000; total++) {
dp[i][total] = dp[i-1][total];
if (total - chef[i] >= 0)
dp[i][total] = max(dp[i][total], dp[i-1][total - chef[i]] + min(chef[i], N));
}
}
int ans = INT_MAX;
for (int total = sum; total <= 90000; total++) {
if (dp[M][total] >= N * K)
ans = min(ans, total - sum);
}
if (ans == INT_MAX)
cout << "Impossible\n";
else
cout << ans << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1364 KB |
Output is correct |
2 |
Correct |
1 ms |
1364 KB |
Output is correct |
3 |
Correct |
1 ms |
1364 KB |
Output is correct |
4 |
Correct |
1 ms |
1364 KB |
Output is correct |
5 |
Correct |
1 ms |
1364 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
1348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1364 KB |
Output is correct |
2 |
Correct |
1 ms |
1364 KB |
Output is correct |
3 |
Correct |
1 ms |
1364 KB |
Output is correct |
4 |
Correct |
1 ms |
1364 KB |
Output is correct |
5 |
Correct |
1 ms |
1364 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
1348 KB |
Output is correct |
9 |
Correct |
4 ms |
5844 KB |
Output is correct |
10 |
Correct |
4 ms |
5844 KB |
Output is correct |
11 |
Correct |
4 ms |
5844 KB |
Output is correct |
12 |
Correct |
5 ms |
5960 KB |
Output is correct |
13 |
Correct |
5 ms |
5844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
68 ms |
92492 KB |
Output is correct |
2 |
Correct |
60 ms |
80248 KB |
Output is correct |
3 |
Correct |
80 ms |
106344 KB |
Output is correct |
4 |
Correct |
81 ms |
106344 KB |
Output is correct |
5 |
Correct |
76 ms |
102740 KB |
Output is correct |
6 |
Correct |
59 ms |
73932 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
14676 KB |
Output is correct |
2 |
Correct |
13 ms |
14676 KB |
Output is correct |
3 |
Correct |
12 ms |
14764 KB |
Output is correct |
4 |
Correct |
13 ms |
14768 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1364 KB |
Output is correct |
2 |
Correct |
1 ms |
1364 KB |
Output is correct |
3 |
Correct |
1 ms |
1364 KB |
Output is correct |
4 |
Correct |
1 ms |
1364 KB |
Output is correct |
5 |
Correct |
1 ms |
1364 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
1348 KB |
Output is correct |
9 |
Correct |
4 ms |
5844 KB |
Output is correct |
10 |
Correct |
4 ms |
5844 KB |
Output is correct |
11 |
Correct |
4 ms |
5844 KB |
Output is correct |
12 |
Correct |
5 ms |
5960 KB |
Output is correct |
13 |
Correct |
5 ms |
5844 KB |
Output is correct |
14 |
Correct |
68 ms |
92492 KB |
Output is correct |
15 |
Correct |
60 ms |
80248 KB |
Output is correct |
16 |
Correct |
80 ms |
106344 KB |
Output is correct |
17 |
Correct |
81 ms |
106344 KB |
Output is correct |
18 |
Correct |
76 ms |
102740 KB |
Output is correct |
19 |
Correct |
59 ms |
73932 KB |
Output is correct |
20 |
Correct |
12 ms |
14676 KB |
Output is correct |
21 |
Correct |
13 ms |
14676 KB |
Output is correct |
22 |
Correct |
12 ms |
14764 KB |
Output is correct |
23 |
Correct |
13 ms |
14768 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
59 ms |
74644 KB |
Output is correct |
26 |
Correct |
63 ms |
86256 KB |
Output is correct |
27 |
Correct |
44 ms |
57044 KB |
Output is correct |
28 |
Correct |
66 ms |
86604 KB |
Output is correct |
29 |
Correct |
67 ms |
88728 KB |
Output is correct |
30 |
Correct |
78 ms |
106344 KB |
Output is correct |