Submission #1169479

#TimeUsernameProblemLanguageResultExecution timeMemory
1169479bbartekJelly Flavours (IOI20_jelly)C++20
100 / 100
169 ms78748 KiB
#include <bits/stdc++.h>
#include "jelly.h"

using namespace std;

typedef long long ll;
#define st first
#define nd second
#define pb push_back

const int maxn = 2003; 

int dp[2003][10003];

int find_maximum_unique(int x, int y, vector<int> a, vector<int> b) {
    vector<pair<int,int>> sortowane;
    int n=a.size();
    for(int i=0;i<n;i++){
        sortowane.pb({a[i],b[i]});
    }
    sort(sortowane.begin(),sortowane.end());

    dp[0][0] = y;
    int wyn=0,akt,ile;
    vector<int> reszta;
    for(int i=0;i<=n;i++){
        if(i > 0){
            for(int j=0;j<=x;j++){
                dp[i][j] = -1e9;
                if(j>0)
                    dp[i][j] = dp[i][j-1];
                if(j >= sortowane[i-1].st)
                    dp[i][j] = max(dp[i][j],dp[i-1][j-sortowane[i-1].st]);
                if(dp[i-1][j] >= sortowane[i-1].nd)
                    dp[i][j] = max(dp[i][j],dp[i-1][j] - sortowane[i-1].nd);
            }
        }
        akt = i;
        if(dp[i][x] < 0)
            break;
        ile = dp[i][x];
        reszta.clear();
        for(int j=i+1;j<=n;j++){
            reszta.pb(sortowane[j-1].nd);   
        }
        sort(reszta.begin(),reszta.end());
        for(auto j : reszta){
            if(j > ile)
                break;
            else{
                ile -= j;
                akt++;
            }
        }
        wyn = max(wyn,akt);
    }
    return wyn;
}
#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...