# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1191412 | nekolie | Detecting Molecules (IOI16_molecules) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
using namespace std;
vector<int> find_subset(int l, int r, vector<int> a) {
int n = a.size();
pair<int,int> risa[n];
for (int i = 0; i < n; i++)
risa[i].first = a[i], risa[i].second = i;
sort(risa,risa+n);
long long suma[n]; suma[0] = risa[0].first;
for (int i = 1; i < n; i++)
suma[i] = suma[i-1]+risa[i].first;
vector<int> odp;
for (int k = 1; k <= n; k++) {
if (suma[k-1] > r || (k < n && suma[n-1]-suma[n-k-1] < l))
continue;
vector<pair<int,int>> op;
for (int i = 0; i < k; i++)
op.push_back({i,n-i-1});
while (op.back().first > op.back().second)
odp.push_back(risa[op[i].first].second), op.pop_back();
long long ile = suma[k-1];
for (int i = 0; i < op.size(); i++) {
if (ile < l)
ile += risa[op[i].second].first-risa[op[i].first].first, odp.push_back(risa[op[i].second].second);
else
odp.push_back(risa[op[i].first].second);
}
break;
}
return odp;
}