답안 #1105870

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1105870 2024-10-28T07:36:41 Z vjudge1 Kitchen (BOI19_kitchen) C++17
100 / 100
102 ms 100680 KB
#include <bits/stdc++.h>

int main() {
    std::ios_base::sync_with_stdio(false); 
    std::cin.tie(nullptr);

    int n, m, k;
    std::cin >> n >> m >> k;
    std::vector<int> a(n), b(m);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }
    for (int i = 0; i < m; i++) {
        std::cin >> b[i];
    }
    int64_t suma = 0;
    int64_t sumb = 0;
    for (int i = 0; i < n; i++) {
        suma += a[i];
    }
    for (int i = 0; i < m; i++) {
        sumb += b[i];
    }
    if (m < k || sumb < suma) {
        std::cout << "Impossible\n";
        return 0;
    }
    for (int i = 0; i < n; i++) {
        if (a[i] < k) {
            std::cout << "Impossible\n";
            return 0;
        }
    }
    std::vector<std::vector<int>> dp(m + 1, std::vector<int>(sumb + 1));
    for (int i = 0; i <= m; i++) {
        for (int j = 0; j <= sumb; j++) {
            dp[i][j] = -1;
        }
    }
    dp[0][0] = 0;
    for (int i = 0; i < m; i++) {
        for (int j = 0; j <= sumb; j++) {
            if (dp[i][j] == -1) {
                continue;
            }
            dp[i + 1][j] = std::max(dp[i + 1][j], dp[i][j]);
            if (j + b[i] <= sumb) {
                dp[i + 1][j + b[i]] = std::max(dp[i + 1][j + b[i]], dp[i][j] + std::min(b[i], n));
            }
        }
    }
    for (int j = suma; j <= sumb; j++) {
        if (dp[m][j] >= n * k) {
            std::cout << j - suma << "\n";
            return 0;
        }
    }
    std::cout << "Impossible\n";
    return 0;
}


# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 504 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 504 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 504 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 504 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 592 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 68944 KB Output is correct
2 Correct 50 ms 51548 KB Output is correct
3 Correct 59 ms 57268 KB Output is correct
4 Correct 100 ms 98388 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 43 ms 41552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 1 ms 592 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 504 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 504 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 592 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 716 KB Output is correct
14 Correct 74 ms 68944 KB Output is correct
15 Correct 50 ms 51548 KB Output is correct
16 Correct 59 ms 57268 KB Output is correct
17 Correct 100 ms 98388 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 43 ms 41552 KB Output is correct
20 Correct 1 ms 592 KB Output is correct
21 Correct 1 ms 592 KB Output is correct
22 Correct 1 ms 592 KB Output is correct
23 Correct 1 ms 592 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 51 ms 50364 KB Output is correct
26 Correct 60 ms 62116 KB Output is correct
27 Correct 19 ms 18512 KB Output is correct
28 Correct 53 ms 51572 KB Output is correct
29 Correct 72 ms 69960 KB Output is correct
30 Correct 102 ms 100680 KB Output is correct