Submission #124860

# Submission time Handle Problem Language Result Execution time Memory
124860 2019-07-04T04:45:06 Z khsoo01 Kitchen (BOI19_kitchen) C++11
100 / 100
30 ms 1528 KB
#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

kitchen.cpp: In function 'int main()':
kitchen.cpp:15:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d",&n,&mt,&k);
  ~~~~~^~~~~~~~~~~~~~~~~~~~
kitchen.cpp:18:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&T);
   ~~~~~^~~~~~~~~
kitchen.cpp:24:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&T);
   ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1400 KB Output is correct
2 Correct 3 ms 1400 KB Output is correct
3 Correct 3 ms 1400 KB Output is correct
4 Correct 3 ms 1400 KB Output is correct
5 Correct 3 ms 1528 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 1400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1400 KB Output is correct
2 Correct 3 ms 1400 KB Output is correct
3 Correct 3 ms 1400 KB Output is correct
4 Correct 3 ms 1400 KB Output is correct
5 Correct 3 ms 1528 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 1400 KB Output is correct
9 Correct 4 ms 1400 KB Output is correct
10 Correct 4 ms 1400 KB Output is correct
11 Correct 4 ms 1400 KB Output is correct
12 Correct 4 ms 1400 KB Output is correct
13 Correct 4 ms 1404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 1404 KB Output is correct
2 Correct 23 ms 1400 KB Output is correct
3 Correct 30 ms 1400 KB Output is correct
4 Correct 29 ms 1400 KB Output is correct
5 Correct 28 ms 1400 KB Output is correct
6 Correct 22 ms 1400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1400 KB Output is correct
2 Correct 7 ms 1400 KB Output is correct
3 Correct 7 ms 1528 KB Output is correct
4 Correct 7 ms 1400 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1400 KB Output is correct
2 Correct 3 ms 1400 KB Output is correct
3 Correct 3 ms 1400 KB Output is correct
4 Correct 3 ms 1400 KB Output is correct
5 Correct 3 ms 1528 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 1400 KB Output is correct
9 Correct 4 ms 1400 KB Output is correct
10 Correct 4 ms 1400 KB Output is correct
11 Correct 4 ms 1400 KB Output is correct
12 Correct 4 ms 1400 KB Output is correct
13 Correct 4 ms 1404 KB Output is correct
14 Correct 26 ms 1404 KB Output is correct
15 Correct 23 ms 1400 KB Output is correct
16 Correct 30 ms 1400 KB Output is correct
17 Correct 29 ms 1400 KB Output is correct
18 Correct 28 ms 1400 KB Output is correct
19 Correct 22 ms 1400 KB Output is correct
20 Correct 6 ms 1400 KB Output is correct
21 Correct 7 ms 1400 KB Output is correct
22 Correct 7 ms 1528 KB Output is correct
23 Correct 7 ms 1400 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 21 ms 1400 KB Output is correct
26 Correct 24 ms 1400 KB Output is correct
27 Correct 17 ms 1400 KB Output is correct
28 Correct 24 ms 1400 KB Output is correct
29 Correct 25 ms 1400 KB Output is correct
30 Correct 30 ms 1400 KB Output is correct