This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "jelly.h"
#include <bits/stdc++.h>
using namespace std;
struct jelly{
int a, b;
};
const int N = 2005;
const int INF = INT_MAX;
jelly v[N];
bool cmpj(jelly a, jelly b){
return a.a < b.a;
}
bool cmpb(jelly a, jelly b){
return a.b < b.b;
}
int dp[N][10005];
int cost[N];
int find_maximum_unique(int x, int y, vector<int> a, vector<int> b) {
int n = a.size();
for(int i=1;i<=n;i++){
v[i] = {a[i-1], b[i-1]};
}
sort(v+ 1, v+n+1, cmpj);
for(int i =0; i <= n;i++){
for(int j = 0; j <= y;j++)
dp[i][j] = INF;
}
dp[0][0] = 0;
for(int i = 1; i<=n;i++){
for(int j = 0; j<=y; j++){
if(dp[i-1][j] == INF)
continue;
dp[i][j] = min(dp[i][j], dp[i-1][j] + v[i].a);
if(j + v[i].b <=y)
dp[i][j + v[i].b] = min(dp[i][j+v[i].b], dp[i-1][j]);
}
}
cost[0] = 0;
for(int i=1; i<=n; i++){
cost[i] = INF;
for(int j = 0;j<=y;j++){
if(dp[i][j] <= x){
cost[i] = j;
break;
}
}
}
int ans = 0;
for(int i= n ;i>=0;i--){
if(cost[i] == INF)
continue;
int ramas = y - cost[i];
sort(v+i+1,v+n+1,cmpb);
int j = i + 1;
int cnt = 0;
while(j <= n && ramas >= 0){
cnt++;
ramas -= v[j].b;
j++;
}
ans = max(ans, i + cnt -1);
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |