Submission #300085

# Submission time Handle Problem Language Result Execution time Memory
300085 2020-09-16T13:58:31 Z BeanZ Kitchen (BOI19_kitchen) C++14
100 / 100
40 ms 1656 KB
// I_LOVE_LPL
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define endl '\n'
const int N = 1e6 + 5;
const int lim = 3e2;
ll dp[N], is[N], a[N];
int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        if (fopen("A.inp", "r")){
                freopen("test.inp", "r", stdin);
                freopen("test.out", "w", stdout);
        }
        ll n, m, k;
        cin >> n >> m >> k;
        ll sum = 0;
        for (int i = 1; i <= n; i++){
                cin >> a[i];
                if (a[i] < k) return cout << "Impossible", 0;
                sum = sum + a[i];
        }
        is[0] = 1;
        for (int i = 1; i <= m; i++){
                ll a;
                cin >> a;
                for (int j = lim * lim; j >= a; j--){
                        if (is[j - a]){
                                ll cost = min(a, n);
                                is[j] = 1;
                                if (dp[j] < (dp[j - a] + cost)){
                                        dp[j] = dp[j - a] + cost;
                                }
                        }
                }
        }
        for (int i = sum; i <= (lim * lim); i++){
                if (dp[i] >= (n * k)){
                        cout << i - sum;
                        return 0;
                }
        }
        cout << "Impossible";
}
/*
*/

Compilation message

kitchen.cpp: In function 'int main()':
kitchen.cpp:15:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   15 |                 freopen("test.inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
kitchen.cpp:16:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   16 |                 freopen("test.out", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 3 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 1400 KB Output is correct
2 Correct 25 ms 1280 KB Output is correct
3 Correct 36 ms 1144 KB Output is correct
4 Correct 38 ms 1656 KB Output is correct
5 Correct 35 ms 1656 KB Output is correct
6 Correct 24 ms 1144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 3 ms 512 KB Output is correct
14 Correct 30 ms 1400 KB Output is correct
15 Correct 25 ms 1280 KB Output is correct
16 Correct 36 ms 1144 KB Output is correct
17 Correct 38 ms 1656 KB Output is correct
18 Correct 35 ms 1656 KB Output is correct
19 Correct 24 ms 1144 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 22 ms 1272 KB Output is correct
26 Correct 30 ms 1304 KB Output is correct
27 Correct 19 ms 768 KB Output is correct
28 Correct 30 ms 1144 KB Output is correct
29 Correct 40 ms 1400 KB Output is correct
30 Correct 39 ms 1656 KB Output is correct