Submission #1338276

#TimeUsernameProblemLanguageResultExecution timeMemory
1338276ninstroyerJelly Flavours (IOI20_jelly)C++20
100 / 100
90 ms78736 KiB
#include "jelly.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long

const int nx = 2e3+5, wx = 1e4+5, inf = 1e9;

int n,res=0,dp[nx][wx];
vector<pair<int,int>> items;

int find_maximum_unique(int x, int y, std::vector<int> a, std::vector<int> b) 
{
	int n = a.size();
	for(int i = 1; i <= n; i++) for(int j = 0; j <= x; j++) dp[i][j]=inf;
	for(int i = 0; i < n; i++) items.push_back({a[i],b[i]});
	sort(items.begin(),items.end());
	for(int i = 1; i <= n; i++)
	{
		auto [aprice,bprice] = items[i-1];
		for(int j = 0; j <= x; j++)
		{
			dp[i][j]=dp[i-1][j]+bprice;
			if(j>=aprice) dp[i][j]=min(dp[i][j],dp[i-1][j-aprice]);
		}
	}
	for(int i = 0; i <= n; i++)
	{
		int mn = inf;
		int cnt = i;
		for(int j = 0; j <= x; j++)
		{
			mn = min(mn,dp[i][j]);
		}
		if(mn > y) continue;
		int budget = y-mn;
		vector<int> item;
		for(int j = i; j < n; j++) item.push_back(items[j].second);
		sort(item.begin(),item.end());
		for(int j = 0; j < item.size(); j++)
		{
			if(item[j]>budget) break;
			cnt++;
			budget-=item[j];
		}
		res = max(res,cnt);
	}
	return res;
}
#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...