Submission #522115

#TimeUsernameProblemLanguageResultExecution timeMemory
522115tabrJelly Flavours (IOI20_jelly)C++17
24 / 100
29 ms31816 KiB
#include <bits/stdc++.h>
using namespace std;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int find_maximum_unique(int x, int y, vector<int> a, vector<int> b) {
    int n = (int) a.size();
    vector<int> order(n);
    iota(order.begin(), order.end(), 0);
    sort(order.begin(), order.end(), [&](int i, int j) { return a[i] - b[i] < a[j] - b[j]; });
    const int inf = (int) 1e9;
    vector<vector<int>> dp1(n + 1, vector<int>(n + 1, inf));
    dp1[0][0] = 0;
    for (int i = 0; i < n; i++) {
        dp1[i + 1] = dp1[i];
        for (int j = i; j >= 0; j--) {
            dp1[i + 1][j + 1] = min(dp1[i + 1][j + 1], dp1[i][j] + a[order[i]]);
        }
    }
    vector<vector<int>> dp2(n + 1, vector<int>(n + 1, inf));
    dp2[0][0] = 0;
    for (int i = 0; i < n; i++) {
        dp2[i + 1] = dp2[i];
        for (int j = i; j >= 0; j--) {
            dp2[i + 1][j + 1] = min(dp2[i + 1][j + 1], dp2[i][j] + b[order[n - 1 - i]]);
        }
    }
    vector<int> c1(n + 1);
    for (int i = 0; i <= n; i++) {
        for (int j = i; j >= 0; j--) {
            if (dp1[i][j] <= x) {
                c1[i] = j;
                break;
            }
        }
    }
    vector<int> c2(n + 1);
    for (int i = 0; i <= n; i++) {
        for (int j = i; j >= 0; j--) {
            if (dp2[i][j] <= y) {
                c2[i] = j;
                break;
            }
        }
    }
    int ans = 0;
    for (int i = 0; i <= n; i++) {
        ans = max(ans, c1[i] + c2[n - i]);
    }
    return ans;
}

#ifdef tabr
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << find_maximum_unique(2, 3, {2, 1, 4}, {2, 3, 2}) << '\n';
    cout << find_maximum_unique(6, 12, {5, 1, 5, 6, 3}, {3, 5, 4, 6, 7}) << '\n';

    return 0;
}
#endif
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...