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 <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include "jelly.h"
using namespace std;
#define D(a) \
cout << #a ": " << (a) << ' ';
const int mxN=2001,maxV=10001;
int dp[maxV];
struct mypair {
int first,second;
bool operator<(const mypair& o) {
if(min(first,second)==min(o.first,o.second)) {
return max(first,second)<max(o.first,o.second);
}
return min(first,second) < min(o.first,o.second);
}
};
int inner(int x, int y, vector<int>& a, vector<int>& b) {
int n=a.size();
vector<mypair> sw; sw.reserve(n);
for(int i=0;i<n;++i){
sw.push_back({a[i],b[i]});
}
sort(sw.begin(),sw.end());
dp[0] = 0;
for(int i=1;i<=x;++i) dp[i] = 1e9;
for(int i=0;i<n;++i) {
bool found = false;
for(int j=x;j>=0;--j) {
int tmp = dp[j]+sw[i].second;
if(j-sw[i].first>=0) {
dp[j] = dp[j-sw[i].first];
} else {
dp[j]=1e9;
}
dp[j] = min(dp[j],tmp);
if(dp[j]<=y) found = true;
}
if(!found) return i;
}
return n;
}
int find_maximum_unique(int x, int y, vector<int> a, vector<int> b) {
int tmp = inner(x, y, a, b);
int tmp2= inner(y,x, b, a);
return max(tmp,tmp2);
}
// int main() {
// cout << find_maximum_unique(11,7,{0, 1, 2, 3, 4, 5, 6, 7, 8},{8, 1, 3, 2, 6, 5, 4, 7, 0}) << endl;
// cout << find_maximum_unique(1,1,{1,2,3},{3,2,1}) << endl;
// cout << find_maximum_unique(1,1,{1,2,3},{3,2,1}) << endl;
// }
# | 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... |