# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1002563 | ocasu | 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>
using namespace std;
std::vector<int> find_subset(int l, int u, std::vector<int> z) {
int n=(int)(w.size());
vector<pair<int,int>> w(n);
for (int i=0; i<n; i++) w[i]={z[i],i};
sort(w.begin(),w.end());
int pre=0, x=0;
for (auto i: w){
if (pre+i.first<l) pre+=i.first, x++;
}
vector<int> ans;
if (x==0){
return {w[0].second};
}
int sum=pre, nxt=x, prev=0;
while (sum<l and nxt<n){
sum-=w[prev].first; sum+=w[nxt].first;
nxt++;
prev++;
}
if (sum<l){
return {};
}
for (int i=prev; i<nxt; i++){
ans.push_back(w[i].second);
}
return ans;
}