This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// from duckindog wth depression
#include<bits/stdc++.h>
using namespace std;
//#define LOCAL
#ifndef LOCAL
#include "molecules.h"
#endif // LOCAL
struct T {
int a, b;
T(int aa, int bb) : a(aa), b(bb) {}
};
const int N = 1e4 + 2;
bool f[2][N];
pair<int, int> trace[N][N];
vector<int> find_subset(int l, int u, vector<int> w) {
int n = w.size();
f[0][w[0]] = f[0][0] = 1;
for (int i = 1; i < n; ++i) {
int it = i & 1;
for (int j = 1; j <= u; ++j) f[it][j] = 0;
for (int j = 1; j <= u; ++j) {
auto &ret = f[it][j];
if (f[1 - it][j]) {
ret = 1;
trace[i][j] = {i - 1, j};
}
if (j - w[i] >= 0 && f[1 - it][j - w[i]]) {
ret = 1;
trace[i][j] = {i - 1, j - w[i]};
}
}
}
vector<int> answer;
int i = n - 1, j = 0;
for (int x = l; x <= u; ++x) if (f[i & 1][x]) j = x;
while (j) {
int pi, pj; tie(pi, pj) = trace[i][j];
if (j > pj) answer.push_back(i);
i = pi; j = pj;
}
return answer;
}
#ifdef LOCAL
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
if (fopen("duck.inp", "r")) {
freopen("duck.inp", "r", stdin);
freopen("duck.out", "w", stdout);
}
int l, u; cin >> l >> u;
int x;
vector<int> input;
while (cin >> x) input.push_back(x);
for (auto i : find_subset(l, u, input))
cout << i << ' ';
}
#endif // LOCAL
# | 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... |