Submission #433036

#TimeUsernameProblemLanguageResultExecution timeMemory
433036ACmachineJelly Flavours (IOI20_jelly)C++17
100 / 100
285 ms77808 KiB
#include "jelly.h"
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k, l) for(int i = (j); i < (k); i += (l))
#define FORD(i, j, k, l) for(int i = (j); i >= (k); i -= (l))
#define REP(i, n) FOR(i, 0, n, 1)
#define REPD(i, n) FORD(i, n, 0, 1)
typedef long long ll;
const int INF = (int)1e9;
int find_maximum_unique(int x, int y, std::vector<int> a, std::vector<int> b) {
	int n = a.size();
    multiset<int> se;
    vector<vector<int>> f(n + 1, vector<int>(y + 1, 0));
    vector<int> sorted(n);
    iota(sorted.begin(), sorted.end(), 0);
    sort(sorted.begin(), sorted.end(), [&](int lhs, int rhs){
        return a[lhs] < a[rhs];
    });
    REPD(i, n - 1){
        se.insert(b[sorted[i]]);
        int curr = 0;
        for(int tm : se){
            curr += tm;
            if(curr <= y)
                f[i][curr]++;
            else
                break;
        }
        FOR(j, 1, y + 1, 1){
            f[i][j] += f[i][j - 1];
        }
    }
    int ans = 0;
    vector<int> dp(x + 1, y);
    vector<int> new_dp(x + 1);
    REP(i, n){
        fill(new_dp.begin(), new_dp.end(), -INF);
        REP(j, x + 1){
            new_dp[j] = dp[j] - b[sorted[i]];
            if(j - a[sorted[i]] >= 0){
                new_dp[j - a[sorted[i]]] = max(new_dp[j - a[sorted[i]]], dp[j]);
            }
        }
        dp.swap(new_dp);
        REP(j, x + 1){
            if(dp[j] >= 0){
                ans = max(ans, i + 1 + f[i + 1][dp[j]]);
            }
        } 
    }
    ans = max(ans, f[0][y]);
	return ans;
}
#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...