# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
935792 | SpyrosAliv | Detecting Molecules (IOI16_molecules) | C++14 | 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;
#define ll long long
#define pll pair<ll, ll>
vector<int> ans(int l, int r, vector<pll> w) {
vector<int> a;
for (int i = l; i < r; i++) {
a.push_back(w[i].second);
}
return a;
}
vector<int> find_subset(ll lb, ll ub, vector<ll> w) {
int n = w.size();
vector<pll> arr;
for (int i = 0; i < n; i++) {
arr.push_back({w[i], i});
}
sort(arr.begin(), arr.end());
int l = 0, r = 0;
ll currSum = 0;
while (r < n) {
while (currSum < lb && r < n) {
currSum += arr[r++].first;
}
while (currSum > ub && l < r) {
currSum -= arr[l++].first;
}
if (currSum >= lb && currSum <= ub) {
return ans(l, r, arr);
}
if (r < n) currSum += arr[r++].first;
}
return {};
}