# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1169464 | bbartek | Jelly Flavours (IOI20_jelly) | C++20 | 0 ms | 0 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) {
pair<int,int> sortowane;
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=1;i<=n;i++){
for(int j=0;j<=x;j++){
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;
ile = dp[i][x];
reszta.clear();
for(int j=i+1;j<=n;j++){
reszta.pb(sortowane[i-1].nd);
}
sort(reszta.begin(),reszta.end());
for(auto j : reszta){
if(j > ile)
break;
ile -= j;
akt++;
}
wyn = max(wyn,akt);
}
return wyn;
}
/*
int main(){
int odp = find_maximum_unique(15,12,{0,0,1,1,1,2,4,9,5},{0,0,1,1,1,2,4,9,5});
cout<<odp<<"\n";
return 0;
}
*/