# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
811062 | manhlinh1501 | 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.
vector<int> find_subset(int l, int r, vector<int> a) {
int n = a.size();
vector<i64> sum(n);
vector<pll> res;
for(int i = 0; i < n; i++)
res.eb(a[i], i);
sort(all(res));
sum.front() = res.front().first;
for(int i = 1; i < n; i++)
sum[i] = sum[i - 1] + res[i].first;
vector<int> ans;
for(int i = 0; i < n; i++) {
int pos = lb(sum, sum[i] - res[i].first + l);
if(pos >= n)
continue;
if(sum[pos] - sum[i] + res[i].first <= r) {
for(int j = i; j <= pos; j++)
ans.eb(res[j].second + 1);
return ans;
}
}
reverse(all(res));
sum.front() = res.front().first;
for(int i = 1; i < n; i++)
sum[i] = sum[i - 1] + res[i].first;
vector<int> ans;
for(int i = 0; i < n; i++) {
int pos = lb(sum, sum[i] - res[i].first + l);
if(pos >= n)
continue;
if(sum[pos] - sum[i] + res[i].first <= r) {
for(int j = i; j <= pos; j++)
ans.eb(res[j].second + 1);
return ans;
}
}
return ans;
}