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 <algorithm>
const int NMAX = 2000;
const int XMAX = 10000;
const int INF = 10 * XMAX;
std::vector < std::pair <int, int> > pairs;
int dp[NMAX + 2][XMAX + 2];
int find_maximum_unique(int x, int y, std::vector<int> a, std::vector<int> b) {
int n = (int)a.size();
for(int i = 0; i < n; i++)
pairs.push_back({a[i], b[i]});
sort(pairs.begin(), pairs.end());
for(int i = 1; i <= n; i++)
for(int bugA = 0; bugA <= x; bugA++)
dp[i][bugA] = INF;
for(int i = 0; i < n; i++)
for(int bugA = 0; bugA <= x; bugA++)
if(dp[i][bugA] <= y)
{
///cumpar i + 1 din A
if(bugA + pairs[i].first <= x)
dp[i + 1][bugA + pairs[i].first] = std::min(dp[i + 1][bugA + pairs[i].first], dp[i][bugA]);
///cumpar i + 1 din B
if(dp[i][bugA] + pairs[i].second <= y)
dp[i + 1][bugA] = std::min(dp[i + 1][bugA], dp[i][bugA] + pairs[i].second);
}
std::vector <int> sufb;
int sol = 0;
for(int i = n; i >= 0; i--)
{
int minY = INF;
for(int bugA = 0; bugA <= x; bugA++)
minY = std::min(minY, dp[i][bugA]);
if(i + 1 <= n)
sufb.push_back(pairs[i].second);
if(minY <= y) {
int placed = i; ///pref
sort(sufb.begin(), sufb.end());
int remBudget = y - minY;
for(auto it : sufb)
if(remBudget >= it) {
remBudget -= it;
placed++;
} else
break;
sol = std::max(sol, placed);
}
}
return sol;
}
# | 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... |