# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
867495 | lolismek | 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 "molecules.h"
#include <algorithm>
#include <iostream>
#include <queue>
#include <cassert>
using namespace std;
vector<int> find_subset(int l, int u, vector<int> w){
queue <int> dq;
long long sum = 0;
vector <pii> v;
for(int i = 0; i < (int)w.size(); i++){
v.push_back({w[i], i});
}
sort(w.begin(), w.end());
sort(v.begin(), v.end());
for(int i = 0; i < (int)w.size(); i++){
sum += w[i];
dq.push(i);
while(!dq.empty() && sum > u){
sum -= w[dq.front()];
dq.pop();
}
if(l <= sum && sum <= u){
vector <int> ans;
while(!dq.empty()){
ans.push_back(v[dq.front()].second);
dq.pop();
}
return ans;
}
}
return {};
}
/*
4 15 17
6 8 8 7
*/