# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
658065 | kusssso | Detecting Molecules (IOI16_molecules) | C++17 | 0 ms | 0 KiB |
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<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
vector<int> find_subset (int l, int u, vector<int> w) {
vector<int> res;
vector<pair<int, int>> v;
int n = w.size();
for (int i = 0; i < n; i++) {
v.push_back({w[i], i});
}
sort(v.begin(), v.end());
vector<int> pf(n, 0);
vector<int> sf(n + 1, 0);
for (int i = 0; i < n; i++) {
pf[i] = (i == 0 ? 0 : pf[i - 1]) + v[i].first;
}
for (int i = n - 1; i >= 0; i--) {
sf[i] = sf[i + 1] + v[i].first;
}
for (int len = 1; len <= n; len++) {
if (pf[len - 1] >= l or sf[n - len] >= l) {
if (pf[len - 1] > u) return {};
for (int i = 0; i + len - 1 < n; i++) {
int sum = pf[i + len - 1] - (i == 0 ? 0 : pf[i - 1]);
if (l <= sum and sum <= u) {
for (int j = i; j < i + len; j++) {
res.push_back(v[j].second);
}
return res;
}
}
}
}
return {};
}