제출 #317919

#제출 시각아이디문제언어결과실행 시간메모리
317919ivan_tudorJelly Flavours (IOI20_jelly)C++14
100 / 100
172 ms78900 KiB
#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];
		if(i < n)
			sort(v+i+1,v+n+1,cmpb);
		int j = i + 1;
		while(j <= n && ramas >= 0){
			ramas -= v[j].b;
			j++;
		}
		if(j == n+1 && ramas >=0)
			ans = n;
		else
			ans = max(ans, i + j - i - 2);
	}
	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...