# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1197265 | andrejikus | Detecting Molecules (IOI16_molecules) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
//#include "molecules.h"
using namespace std;
typedef long long ll;
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) { cerr << to_string(h); if(sizeof...(t)) cerr << ", "; DBG(t...); }
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
const int N = 1e4 + 3;
int dp[N];
vector<int> find_subset(int l, int u, vector<int> w) {
for (int i = 0; i < N; i++) dp[i] = -1;
vector<int> res;
dp[0] = 0;
for (int i = 0; i < w.size(); i++) {
for (int j = 0; j <= u; j++) {
if (j-w[i] < 0) continue;
if (dp[j-w[i]] == -1 || dp[j-w[i]] == i+1) continue;
dp[j] = i+1;
}
}
for (int t = l; t <= u; t++) {
if (dp[t] == -1) continue;
int j = t;
while (j != 0) {
res.push_back(dp[j]-1);
j -= w[dp[j]-1];
}
if (j == 0) break;
}
sort(res.begin(), res.end());
return res;
}
int main() {
int n, l, u;
assert(3 == scanf("%d %d %d", &n, &l, &u));
std::vector<int> w(n);
for (int i = 0; i < n; i++)
assert(1 == scanf("%d", &w[i]));
std::vector<int> result = find_subset(l, u, w);
printf("%d\n", (int)result.size());
for (int i = 0; i < (int)result.size(); i++)
printf("%d%c", result[i], " \n"[i == (int)result.size() - 1]);
}
/*
4 15 17
6 8 8 7
4 15 16
5 5 6 6
4 10 20
15 17 16 18
*/