# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1263639 | piolk | Detecting Molecules (IOI16_molecules) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
vector<int> find_subset(int l,int r,vector<ll> w){
unordered_map<int,vector<int>> wyst; // value,index
for (int i=0;i<w.size();i++) wyst[w[i]].push_back(i);
sort(w.begin(),w.end());
int n=w.size();
int R=-1;
int L=0;
ll sum=0;
while (R<n-1){
R++;
sum+=w[R];
while (sum>r && L<R){
sum-=w[L];
L++;
}
if (sum>=l && sum<=r){
vector<int> indices;
for (int i=L;i<=R;i++){
int index=wyst[w[i]].back();
wyst[w[i]].pop_back();
indices.push_back(index);
}
return indices;
}
}
return {};
}