# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
867284 | AtabayRajabli | 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 "molecules.h"
#include <bits/stdc++.h>
#define int long long
using namespace std;
std::vector<int> find_subset(int L, int U, std::vector<int> w) {
int n = w.size();
std::vector<pair<int, int>> v(n);
for(int i = 0; i<n; i++)
{
v[i] = make_pair(w[i], i);
}
sort(v.begin(), v.end());
set<int> s;
int l = 0, r = 0, sum = 0;
while(r < n)
{
sum += v[r].first;
s.insert(v[r].second);
while(l <= r && sum > U)
{
sum -= v[l].first;
s.erase(v[l].second);
l++;
}
if(L <= sum && sum <= U)
{
vector<int> ans;
for(int i : s)ans.push_back(i);
return ans;
}
r++;
}
return std::vector<int>(0);
}