Submission #584344

# Submission time Handle Problem Language Result Execution time Memory
584344 2022-06-27T08:33:15 Z tengiz05 Kitchen (BOI19_kitchen) C++17
100 / 100
68 ms 596 KB
#include <bits/stdc++.h>

using i64 = long long;

void chmax(int &a, int b) {
    if (a < b)
        a = b;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int n, m, k;
    std::cin >> n >> m >> k;
    
    std::vector<int> a(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
        if (a[i] < k) {
            std::cout << "Impossible\n";
            return 0;
        }
    }
    
    std::vector<int> b(m);
    for (int i = 0; i < m; i++) {
        std::cin >> b[i];
    }
    
    int sum = std::accumulate(a.begin(), a.end(), 0);
    int N = std::accumulate(b.begin(), b.end(), 0);
    
    std::vector<int> dp(N + 1, -1E9);
    dp[0] = 0;
    
    for (int i = 0; i < m; i++) {
        for (int j = N - b[i]; j >= 0; j--) {
            chmax(dp[j + b[i]], dp[j] + std::min(n, b[i]));
        }
    }
    
    int ans = 1E9;
    
    for (int i = sum; i <= N; i++) {
        if (dp[i] >= n * k) {
            ans = std::min(ans, i - sum);
        }
    }
    
    if (ans == 1E9) {
        std::cout << "Impossible\n";
    } else {
        std::cout << ans << "\n";
    }
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 468 KB Output is correct
2 Correct 35 ms 468 KB Output is correct
3 Correct 34 ms 468 KB Output is correct
4 Correct 68 ms 596 KB Output is correct
5 Correct 62 ms 596 KB Output is correct
6 Correct 26 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 41 ms 468 KB Output is correct
15 Correct 35 ms 468 KB Output is correct
16 Correct 34 ms 468 KB Output is correct
17 Correct 68 ms 596 KB Output is correct
18 Correct 62 ms 596 KB Output is correct
19 Correct 26 ms 504 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 31 ms 468 KB Output is correct
26 Correct 42 ms 468 KB Output is correct
27 Correct 15 ms 340 KB Output is correct
28 Correct 38 ms 452 KB Output is correct
29 Correct 42 ms 596 KB Output is correct
30 Correct 68 ms 596 KB Output is correct