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<bits/stdc++.h>
using namespace std;
typedef array<int, 2> pii;
int find_maximum_unique(int x, int y, vector<int> a, vector<int> b){
int n = a.size();
vector<pii> c(n);
for(int i = 0; i < n; ++i) c[i] = {a[i], b[i]};
sort(c.begin(), c.end());
vector<vector<int>> v(n+1, vector<int>(x+1)), w(n+1, vector<int>(y+1));
// v: buy i cheapest jelly, given money spent in a, find min extra cost in b
for(int i = 1; i <= n; ++i){
for(int j = 0; j <= x; ++j){
v[i][j] = v[i-1][j] + c[i-1][1];
if(j >= c[i-1][0]) v[i][j] = min(v[i][j], v[i-1][j-c[i-1][0]]);
}
}
// w: buy in b jelly that would be expensive in a, find max jelly
for(int i = n-1; i >= 0; --i){
for(int j = 0; j <= y; ++j){
w[i][j] = w[i+1][j];
if(j >= c[i][1]) w[i][j] = max(w[i][j], w[i+1][j-c[i][1]]+1);
}
}
int ans = 0;
for(int i = 0; i <= n; ++i){
int yy = y - v[i][x];
if(yy >= 0) ans = max(ans, i + w[i][yy]);
}
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... |