Submission #151201

# Submission time Handle Problem Language Result Execution time Memory
151201 2019-09-02T06:54:48 Z georgerapeanu Kitchen (BOI19_kitchen) C++11
100 / 100
53 ms 1144 KB
#include <cstdio>
#include <algorithm>

using namespace std;

const int NMAX = 300;
const int SMAX = NMAX * NMAX;

int n,m,k;
int a[NMAX + 5];
int b[NMAX + 5];
int dp[2][SMAX + 5];
int sum;

int update(int x,int y,int val){
    if(y < 0 || y > SMAX || dp[x][y] == -1){
        return -1;
    }
    return dp[x][y] + val;
}

int main(){

    scanf("%d %d %d",&n,&m,&k);
    
    for(int i = 1;i <= n;i++){
        scanf("%d",&a[i]);
        sum += a[i];
        if(a[i] < k){
            printf("Impossible");
            return 0;
        }
    }
    
    for(int i = 1;i <= m;i++){
        scanf("%d",&b[i]);
    }

    for(int i = 0;i < 2;i++){
        for(int j = 0;j <= SMAX;j++){
            dp[i][j] = -1;
        }
    }

    dp[0][0] = 0;

    for(int i = 1,l = 1;i <= m;i++,l ^= 1){
        for(int j = 0;j <= SMAX;j++){
            dp[l][j] = dp[l ^ 1][j];
            dp[l][j] = max(dp[l][j],update(l ^ 1,j - b[i],min(n,b[i])));
        }
    }

    for(int i = sum;i <= SMAX;i++){
        if(dp[m & 1][i] >= k * n){
            printf("%d\n",i - sum);
            return 0;
        }
    }
    printf("Impossible");
    
    return 0;
}

Compilation message

kitchen.cpp: In function 'int main()':
kitchen.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d",&n,&m,&k);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~
kitchen.cpp:27:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&a[i]);
         ~~~~~^~~~~~~~~~~~
kitchen.cpp:36:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&b[i]);
         ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1016 KB Output is correct
2 Correct 3 ms 1016 KB Output is correct
3 Correct 3 ms 1016 KB Output is correct
4 Correct 3 ms 1016 KB Output is correct
5 Correct 3 ms 1016 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 1016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1016 KB Output is correct
2 Correct 3 ms 1016 KB Output is correct
3 Correct 3 ms 1016 KB Output is correct
4 Correct 3 ms 1016 KB Output is correct
5 Correct 3 ms 1016 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 1016 KB Output is correct
9 Correct 5 ms 1016 KB Output is correct
10 Correct 5 ms 1016 KB Output is correct
11 Correct 5 ms 1016 KB Output is correct
12 Correct 5 ms 1016 KB Output is correct
13 Correct 5 ms 1016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 1016 KB Output is correct
2 Correct 39 ms 1016 KB Output is correct
3 Correct 53 ms 1016 KB Output is correct
4 Correct 51 ms 1084 KB Output is correct
5 Correct 49 ms 1016 KB Output is correct
6 Correct 36 ms 1048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 1016 KB Output is correct
2 Correct 9 ms 1016 KB Output is correct
3 Correct 10 ms 1016 KB Output is correct
4 Correct 9 ms 1020 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1016 KB Output is correct
2 Correct 3 ms 1016 KB Output is correct
3 Correct 3 ms 1016 KB Output is correct
4 Correct 3 ms 1016 KB Output is correct
5 Correct 3 ms 1016 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 1016 KB Output is correct
9 Correct 5 ms 1016 KB Output is correct
10 Correct 5 ms 1016 KB Output is correct
11 Correct 5 ms 1016 KB Output is correct
12 Correct 5 ms 1016 KB Output is correct
13 Correct 5 ms 1016 KB Output is correct
14 Correct 46 ms 1016 KB Output is correct
15 Correct 39 ms 1016 KB Output is correct
16 Correct 53 ms 1016 KB Output is correct
17 Correct 51 ms 1084 KB Output is correct
18 Correct 49 ms 1016 KB Output is correct
19 Correct 36 ms 1048 KB Output is correct
20 Correct 9 ms 1016 KB Output is correct
21 Correct 9 ms 1016 KB Output is correct
22 Correct 10 ms 1016 KB Output is correct
23 Correct 9 ms 1020 KB Output is correct
24 Correct 2 ms 256 KB Output is correct
25 Correct 36 ms 1016 KB Output is correct
26 Correct 41 ms 1016 KB Output is correct
27 Correct 28 ms 1016 KB Output is correct
28 Correct 42 ms 1144 KB Output is correct
29 Correct 42 ms 1016 KB Output is correct
30 Correct 51 ms 1020 KB Output is correct