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 <vector>
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e3 + 10;
const int MAXM = 1e4 + 10;
int dp[MAXN][MAXM];
int calc(int i, int x, int y, int N, vector<int> &a, vector<int> &b)
{
	// cerr << dp[i][y] << " " << i << " " << y << "\n";
	if(x < 0 || y < 0) return -1;
	// if(x < 0) return calc(i + 1,0,y,N,a,b);
	if(dp[i][y] != -1) return dp[i][y];
	// if(i == 2) cerr << "aq\n";
	if(i > N) return 0;
	int op1;
	if(x - a[i - 1] >= 0)
		op1 = calc(i + 1, x - a[i - 1], y, N, a, b) + 1;
	else
		op1 = calc(i + 1, x, y, N, a, b);
	int op2 = calc(i + 1, x, y - b[i - 1], N , a, b) + 1;
	// int op3 = calc(i + 1,x,y,N,a,b);
	dp[i][y] = max(op1,op2);
	// cerr << dp[i][y] << " " << i << " " << y << "\n";
	return dp[i][y];
}
bool cmp(pair<int,int> a, pair<int,int> b)
{
	if(a.first == b.first) return a.second < b.second;
	return a.first < b.first;
}
int find_maximum_unique(int x, int y, std::vector<int> a, std::vector<int> b) {
	int N = a.size();
	vector<pair<int,int>> aux;
	for(int i = 0; i < N; i++)
	{
		aux.push_back({a[i],b[i]});
	}
	for(int i = 0; i <= N + 2; i++)
	{
		for(int j = 0; j <= y + 2; j++)
			dp[i][j] = -1;
	}
	a.clear();
	b.clear();
	sort(aux.begin(),aux.end(),cmp);
	int comp = 0;
	for(int i = 0; i < N; i++)
	{
		if(aux[i].first == 0 || aux[i].second == 0)
		{
			comp++;
			continue;
		}
		a.push_back(aux[i].first);
		b.push_back(aux[i].second);
		// cerr << a[i] << " " << b[i] << "\n";
	}
	N = a.size();
	return calc(1,x,y,N,a,b) + comp;
}
| # | 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... |