Submission #854656

# Submission time Handle Problem Language Result Execution time Memory
854656 2023-09-28T10:25:58 Z vjudge1 Kitchen (BOI19_kitchen) C++17
0 / 100
17 ms 856 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));
                }
                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 = 0; i <= sum; i++) {
                if (f[i].first >= k) {
                        cout << i - accumulate(a.begin(), a.end(), 0);
                        return 0;
                }
        }
        cout << "Impossible";
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1 ms 452 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1 ms 452 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 856 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Runtime error 1 ms 604 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1 ms 452 KB Output isn't correct
3 Halted 0 ms 0 KB -