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 "molecules.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> find_subset(int l, int u, std::vector<int> w) {
int n = w.size();
vector <pair <int, int>> dp(u+1, {1e9, -1});
dp[0].first = 0;
for (int i = 0; i < n; i++) {
for (int j = u; j >= w[i]; j--) {
if (dp[j - w[i]].first + w[i] < dp[j].first) {
dp[j].first = dp[j - w[i]].first + w[i];
dp[j].second = i;
}
}
}
vector <int> ans;
int st = -1;
for (int i = l; i <= u; i++) {
if (dp[i].second != -1) {
st = i;
break;
}
}
// cout << "MOI: " << st << '\n';
if (st == -1)
return ans;
while (st > 0) {
int nxt = dp[st].second;
// cout << "MOI: " << nxt << ' ' << w[nxt] << '\n';
ans.push_back(nxt);
st = st - w[nxt];
}
return ans;
}
# | 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... |