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;break;
}
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){
int dp [n+1][x+1][y+1];
memset(dp,0,sizeof dp);
for (int i =1;i<=n;++i){
for (int j =0;j<=x;++j){
for (int k =0;k<=y;++k){
dp[i][j][k] = max({(j-arr[i-1]>=0)?dp[i-1][j-arr[i-1]][k]+1:0,(k-brr[i-1]>=0)?dp[i-1][j][k-brr[i-1]]+1:0,dp[i-1][j][k],dp[i][j][k]});
}
}
}
return dp[n][x][y];}
else {
int ans=0,ans2=0;
vector<pair<int,int>>crr(n);
for (int i=0;i<n;++i){
crr[i]={arr[i],brr[i]};
}
int temp1=x,temp2=y;
sort(crr.begin(),crr.end(),[&](pair<int,int>a,pair<int,int>b){
if (a.first==b.first){
return a.second<b.second;
}
return a.first<b.first;
});
for (int i =0;i<n;++i){
if (x-crr[i].first<y-crr[i].second ){
if (y-crr[i].second<0)continue;
y-=crr[i].second;
ans++;
}
else {
if (x-crr[i].first<0)continue;
x-=crr[i].first;
ans++;
}
}
x=temp1,y=temp2;
for (int i =0;i<n;++i){
if (x-crr[i].first>y-crr[i].second ){
if (x-crr[i].first<0)continue;
x-=crr[i].first;
ans2++;
}
else {
if (y-crr[i].second<0)continue;
y-=crr[i].second;
ans2++;
}
}
return max(ans,ans2);
}
}
# | 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... |