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 <cstdio>
#include <cassert>
#include <vector>
#include<bits/stdc++.h>
using namespace std;
int find_maximum_unique(int x, int y, std::vector<int> arr, std::vector<int> brr) {
int n = arr.size();
bool ok=true;
bool okay=true;
for (int i =0;i<n;++i){
if (arr[i]!=brr[i]){
ok=false;
}
if (i>0){
if (brr[i]!=brr[i-1])okay=false;
}
}
if (okay){
vector<pair<int,int>>crr(n);
for (int i=0;i<n;++i){
crr[i]={arr[i],brr[i]};
}
sort(crr.begin(),crr.end());
int ans=0;
n--;
while(n>=0){
if (y-crr[n].second>=0){
y-=crr[n].second;
--n;
ans++;
}
else break;
}
for (int i =0;i<=n;++i){
if (x-crr[i].first<0)break;
x-=crr[i].first;
ans++;
}
return ans;
}
if (!ok){
vector<pair<int,int>>crr;
for(int i =0;i<n;++i){
crr.push_back({brr[i],arr[i]});
}
sort(crr.begin(),crr.end());
vector<pair<int,int>>dp(x+1,{-1,-1});
dp[0]={0,0};
for (int i =0;i<n;++i){
for (int j =x;j>=0;--j){
if (dp[j].first==-1)continue;
if (j+crr[i].second<=x&&(dp[j+crr[i].second].first==-1||dp[j+crr[i].second].first<dp[j].first+1||dp[j+crr[i].second].second>dp[j].second)){
dp[j+crr[i].second].first = dp[j].first+1;
dp[j+crr[i].second].second=dp[j].second;
}
if (dp[j].second+crr[i].first<=y){
dp[j].second=dp[j].second+crr[i].first;
dp[j].first=dp[j].first+1;
}
}
}
int ans=0;
for (int i =0;i<=x;++i){
if (dp[i].second<=y)
ans=max(ans,dp[i].first);
}
return ans;
}
else {
int dp1[n+1][x+y+1];
memset(dp1,0,sizeof dp1);
for (int i =1;i<=n;++i){
for (int j =0;j<=x+y;++j){
dp1[i][j] = max({(j-arr[i-1]>=0)?dp1[i-1][j-arr[i-1]]+1:0,dp1[i][j],dp1[i-1][j]});
}
}
return dp1[n][x+y];
}
}
# | 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... |