#include "jelly.h"
#include <bits/stdc++.h>
using namespace std;
int n; // liczba produktów w każdym ze sklepów
int x; // pieniądze do wydania w sklepie A
int y; // pieniądze do wydania w sklepie B
vector<int> a; // ceny produktów w sklepie A
vector<int> b; // ceny produktów w sklepie B
int calc_res(int m) {
int sum_x = 0, sum_y = 0, cnt_diff = 0;
for (int i=0; i<n; i++) {
bool temp = false;
if (m & (1 << i)) {
sum_x += a[i];
temp = true;
}
if (m & (1 << (i+n))) {
sum_y += b[i];
temp = true;
}
if (temp) cnt_diff++;
}
if (sum_x > x || sum_y > y) return 0;
return cnt_diff;
}
int brute_exp() {
int max_res = 0;
for (int i=0; i<(1<<(2*n)); i++) {
max_res = max(max_res, calc_res(i));
}
return max_res;
}
int brute_y_equals_to_0() {
sort(a.begin(), a.end());
int res = 0;
int budget = x;
for (int i=0; i<n; i++) {
if (budget - a[i] >= 0) {
budget -= a[i];
res++;
}
}
return res;
}
int find_maximum_unique(int _x, int _y, std::vector<int> _a, std::vector<int> _b) {
n = _a.size();
x = _x;
y = _y;
a = _a;
b = _b;
if (x <= 500 && y <= 500 && n <= 12) return brute_exp();
if (y == 0) return brute_y_equals_to_0();
return 0;
}
# | 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... |