답안 #854673

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
854673 2023-09-28T12:33:58 Z vjudge1 Kitchen (BOI19_kitchen) C++17
100 / 100
49 ms 1368 KB
#include <bits/stdc++.h>
using namespace std;

int32_t main() {
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        int n, m, k;
        cin >> n >> m >> k;
        vector<int> a(n), b(m);
        for (int i = 0; i < n; i++) cin >> a[i];
        for (int i = 0; i < n; i++) {
                if (a[i] < k) {
                        cout << "Impossible";
                        return 0;
                }
        }
        for (int i = 0; i < m; i++) cin >> b[i];
        int limit = *max_element(a.begin(), a.end());
        vector<int> aa(limit);
        for (int i = 0; i < limit; i++) {
                for (int j = 0; j < n; j++) {
                        aa[i] += a[j] > i;
                }
        }
        sort(b.begin(), b.end(), greater<int>());
        int sum = accumulate(b.begin(), b.end(), 0);
        vector<pair<int, int>> f(sum + 1, make_pair(-1, -1));
        f[0] = make_pair(0, 0);
        int s = 0;

        auto get = [&](pair<int, int> a, int b) {
                if (a.first == limit) return make_pair(limit, 0);
                assert(a.second != aa[a.first]);
                int x = a.second;
                a.second += b;
                if (a.second >= aa[a.first]) {
                        a.second %= aa[a.first];
                        a.first++;
                        a.second = a.first == limit ? 0 : min(aa[a.first], min(a.second, x));
if(a.first != limit && a.second == aa[a.first]) a.second = 0, a.first++;
                }
                return a;
        };

        for (int i = 0; i < m; i++) {
                for (int j = s; j >= 0; j--) {
                        if (f[j].first == -1) continue;
                        f[j + b[i]] = max(f[j + b[i]], get(f[j], b[i]));
                }
                s += b[i];
        }

        for (int i = accumulate(a.begin(),a.end(),0); i <= sum; i++) {
                if (f[i].first >= k) {
                        cout << i - accumulate(a.begin(), a.end(), 0);
                        return 0;
                }
        }
        cout << "Impossible";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 856 KB Output is correct
2 Correct 6 ms 860 KB Output is correct
3 Correct 34 ms 604 KB Output is correct
4 Correct 49 ms 1112 KB Output is correct
5 Correct 38 ms 1116 KB Output is correct
6 Correct 4 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 452 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 16 ms 856 KB Output is correct
15 Correct 6 ms 860 KB Output is correct
16 Correct 34 ms 604 KB Output is correct
17 Correct 49 ms 1112 KB Output is correct
18 Correct 38 ms 1116 KB Output is correct
19 Correct 4 ms 604 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 600 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 452 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 5 ms 856 KB Output is correct
26 Correct 7 ms 860 KB Output is correct
27 Correct 11 ms 604 KB Output is correct
28 Correct 29 ms 860 KB Output is correct
29 Correct 35 ms 860 KB Output is correct
30 Correct 48 ms 1368 KB Output is correct