# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
984450 |
2024-05-16T16:49:40 Z |
OAleksa |
Kitchen (BOI19_kitchen) |
C++14 |
|
146 ms |
2700 KB |
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
const int N = 310;
int n, m, k, a[N], b[N];
pair<int, int> dp[N * N], ndp[N * N];
int dp2[N * N], dp3[N * N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tt = 1;
//cin >> tt;
while (tt--) {
cin >> n >> m >> k;
for (int i = 1;i <= n;i++)
cin >> a[i];
sort(a + 1, a + n + 1);
for (int i = 1;i <= m;i++)
cin >> b[i];
if (m < k || a[1] < k)
cout << "Impossible";
else {
dp[0] = {1, 0};
for (int i = 1;i <= m;i++) {
for (int j = 0;j < N * N;j++) {
if (j < b[i]) {
dp3[j] = dp2[j];
ndp[j] = dp[j];
}
else {
if (dp[j - b[i]].f) {
ndp[j] = dp[j - b[i]];
ndp[j].s += 1;
}
if (dp[j].f && dp[j].s > ndp[j].s)
ndp[j] = dp[j];
dp3[j] = dp2[j];
if ((j >= n * k && j - b[i] < n * k && ndp[j].s >= k) || (ndp[j].s >= k && dp[j - b[i]].s < k && j >= n * k)) {
if (ndp[j].f)
dp3[j] = 1;
}
dp3[j] = (dp3[j] | dp2[j - b[i]]);
}
}
for (int i = 0;i < N * N;i++) {
dp[i] = ndp[i], ndp[i] = {0, 0};
dp2[i] = dp3[i], dp3[i] = 0;
}
}
int s = 0, ans = 1e9;
for (int i = 1;i <= n;i++)
s += a[i];
for (int i = N * N - 1;i >= s;i--) {
if (dp2[i])
ans = i - s;
}
if (ans == 1e9)
cout << "Impossible\n";
else
cout << ans << '\n';
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2648 KB |
Output is correct |
2 |
Correct |
2 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
2 ms |
2648 KB |
Output is correct |
5 |
Correct |
3 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2648 KB |
Output is correct |
2 |
Correct |
2 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
2 ms |
2648 KB |
Output is correct |
5 |
Correct |
3 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
2652 KB |
Output is correct |
9 |
Correct |
7 ms |
2652 KB |
Output is correct |
10 |
Correct |
7 ms |
2652 KB |
Output is correct |
11 |
Incorrect |
8 ms |
2648 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
109 ms |
2696 KB |
Output is correct |
2 |
Correct |
97 ms |
2700 KB |
Output is correct |
3 |
Correct |
146 ms |
2700 KB |
Output is correct |
4 |
Correct |
138 ms |
2648 KB |
Output is correct |
5 |
Correct |
134 ms |
2696 KB |
Output is correct |
6 |
Correct |
84 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
2648 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2648 KB |
Output is correct |
2 |
Correct |
2 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
2 ms |
2648 KB |
Output is correct |
5 |
Correct |
3 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
2652 KB |
Output is correct |
9 |
Correct |
7 ms |
2652 KB |
Output is correct |
10 |
Correct |
7 ms |
2652 KB |
Output is correct |
11 |
Incorrect |
8 ms |
2648 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |