# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
124860 | khsoo01 | Kitchen (BOI19_kitchen) | C++11 | 30 ms | 1528 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
const int N = 305, inf = 1e9;
int n, mt, m[2], k, s, a[2][N], dt[2][N*N], mn[N*N], ans = inf;
void boom () {
puts("Impossible");
exit(0);
}
int main()
{
scanf("%d%d%d",&n,&mt,&k);
for(int i=1;i<=n;i++) {
int T;
scanf("%d",&T);
if(T < k) boom();
s += T;
}
for(int i=1;i<=mt;i++) {
int T;
scanf("%d",&T);
int I = (T >= n);
a[I][++m[I]] = T;
}
for(int x=0;x<2;x++) {
fill(dt[x] + 1, dt[x] + N*N, -inf);
for(int i=1;i<=m[x];i++) {
for(int j=N*N-1;j>=a[x][i];j--) {
dt[x][j] = max(dt[x][j], dt[x][j-a[x][i]] + 1);
}
}
}
for(int i=N*N,j=N*N;i--;) {
if(dt[0][i] >= 0) j = i;
mn[i] = j;
}
for(int i=0;i<N*N;i++) {
if(dt[1][i] < 0) continue;
int X = max({0, s - i, (k - dt[1][i]) * n});
if(mn[X] == N*N) continue;
ans = min(ans, i + mn[X]);
}
if(ans == inf) boom();
printf("%d\n", ans - s);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |