Submission #586943

# Submission time Handle Problem Language Result Execution time Memory
586943 2022-07-01T05:52:39 Z 반딧불(#8396) Kitchen (BOI19_kitchen) C++17
100 / 100
80 ms 1084 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n, m, k;
int a[302], b[302];
int S;
int DP[2][100002];
int ans = 1e9;

int main(){
    scanf("%d %d %d", &n, &m, &k);
    for(int i=1; i<=n; i++) scanf("%d", &a[i]);
    for(int i=1; i<=m; i++) scanf("%d", &b[i]);
    sort(a+1, a+n+1);
    if(a[1] < k || m < k || accumulate(a+1, a+n+1, 0) > accumulate(b+1, b+m+1, 0)){
        puts("Impossible");
        return 0;
    }
    S = accumulate(a+1, a+n+1, 0);
    for(int i=0; i<2; i++) for(int j=0; j<=100000; j++) DP[i][j] = -1e9;
    DP[0][0] = 0;
    for(int i=1; i<=m; i++){
        int bit = i%2;
        for(int j=0; j<=100000; j++) DP[bit][j] = -1e9;
        for(int j=0; j<=100000; j++){
            if(DP[!bit][j] == -1e9) continue;
            DP[bit][j] = max(DP[bit][j], DP[!bit][j]);
            DP[bit][j+b[i]] = max(DP[bit][j+b[i]], DP[!bit][j] + min(n, b[i]));
        }
    }
    for(int i=S; i<=100000; i++) if(DP[m%2][i] >= n*k) ans = min(ans, i);
    if(ans == 1e9) printf("Impossible");
    else printf("%d", ans-S);
}

Compilation message

kitchen.cpp: In function 'int main()':
kitchen.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     scanf("%d %d %d", &n, &m, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
kitchen.cpp:15:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     for(int i=1; i<=n; i++) scanf("%d", &a[i]);
      |                             ~~~~~^~~~~~~~~~~~~
kitchen.cpp:16:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     for(int i=1; i<=m; i++) scanf("%d", &b[i]);
      |                             ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 1064 KB Output is correct
3 Correct 1 ms 1076 KB Output is correct
4 Correct 2 ms 1080 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 304 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 1064 KB Output is correct
3 Correct 1 ms 1076 KB Output is correct
4 Correct 2 ms 1080 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 304 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 3 ms 980 KB Output is correct
10 Correct 3 ms 980 KB Output is correct
11 Correct 3 ms 1072 KB Output is correct
12 Correct 3 ms 980 KB Output is correct
13 Correct 3 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 1080 KB Output is correct
2 Correct 44 ms 980 KB Output is correct
3 Correct 68 ms 1072 KB Output is correct
4 Correct 80 ms 980 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 36 ms 1068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 980 KB Output is correct
2 Correct 5 ms 980 KB Output is correct
3 Correct 8 ms 1084 KB Output is correct
4 Correct 6 ms 1072 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 1064 KB Output is correct
3 Correct 1 ms 1076 KB Output is correct
4 Correct 2 ms 1080 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 304 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 3 ms 980 KB Output is correct
10 Correct 3 ms 980 KB Output is correct
11 Correct 3 ms 1072 KB Output is correct
12 Correct 3 ms 980 KB Output is correct
13 Correct 3 ms 980 KB Output is correct
14 Correct 43 ms 1080 KB Output is correct
15 Correct 44 ms 980 KB Output is correct
16 Correct 68 ms 1072 KB Output is correct
17 Correct 80 ms 980 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 36 ms 1068 KB Output is correct
20 Correct 5 ms 980 KB Output is correct
21 Correct 5 ms 980 KB Output is correct
22 Correct 8 ms 1084 KB Output is correct
23 Correct 6 ms 1072 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 35 ms 1068 KB Output is correct
26 Correct 44 ms 1068 KB Output is correct
27 Correct 38 ms 1072 KB Output is correct
28 Correct 57 ms 1076 KB Output is correct
29 Correct 63 ms 1068 KB Output is correct
30 Correct 79 ms 1076 KB Output is correct