#include "jelly.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb push_back
#define pii pair<int,int>
#define pl pair<ll,ll>
#define F first
#define S second
#define pq priority_queue
#define all(x) x.begin(), x.end()
#define deb(x) cout << #x << " = " << x << '\n';
#define deb2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << '\n';
//cena moze byc rowna 0
bool chek(vector<int> a, int x, int y, int v){
int dp[x+1][v+1];
int mtak = 0;
for(int i = 0; i <= v; i++){
dp[0][i] = 1;
for(int j = 1; j <= x; j++){
dp[j][i] = 0;
if(i > 0){
dp[j][i] = dp[j][i-1];
if(j >= a[i-1]){
if(dp[j-a[i-1]][i-1] == 1){
dp[j][i] = 1;
mtak = max(mtak, j);
}
}
}
}
}
int sum = 0;
for(int i = 0; i < v; i++) sum += a[i];
return y >= sum-mtak;
}
int find_maximum_unique(int x, int y, vector<int> a, vector<int> b) {
int n = a.size();
bool p5 = 1;
for(int i = 0; i < n; i++){
if(a[i] != b[i]) p5 = 0;
}
if(x <= 500 && y <= 500 && n <= 200){
int dp[x+7][y+7][n+7];
for(int x1 = 0; x1 <= x; x1++){
for(int y1 = 0; y1 <= y; y1++){
dp[x1][y1][0] = 0;
}
}
for(int x1 = 0; x1 <= x; x1++){
for(int y1 = 0; y1 <= y; y1++){
for(int i = 1; i <= n; i++){
dp[x1][y1][i] = dp[x1][y1][i-1];
if(x1 >= a[i-1]) dp[x1][y1][i] = max(dp[x1][y1][i], dp[x1-a[i-1]][y1][i-1]+1);
if(y1 >= b[i-1]) dp[x1][y1][i] = max(dp[x1][y1][i], dp[x1][y1-b[i-1]][i-1]+1);
}
}
}
return dp[x][y][n];
}
else if(y == 0){
int sc = 0;
for(int i = 0; i < n; i++) if(b[i] == 0) a[i] = 0;
sort(all(a));
int ind = 0;
for(int i = 0; i < n; i++){
if(a[i] <= x){
x -= a[i];
sc++;
}
}
return sc;
}
else if(p5){
sort(all(a));
int bes = 0;
int l = 0, r = n;
while(r-l > 1){
int mid = (l+r)/2;
if(chek(a,x,y,mid)) l = mid;
else r = mid-1;
}
if(chek(a,x,y,r)) bes = r;
else bes = l;
int sum = 0;
for(int i = 0; i < bes; i++) sum += a[i];
return sum;
}
else{
int sc = 0;
sort(all(a));
for(int i = 0; i < n; i++){
if(a[i] <= x){
x -= a[i];
sc++;
}
else if(b[i] <= y){
y -= b[i];
sc++;
}
}
return sc;
}
return n;
}
# | 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... |