# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
882120 | andro | 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>
#define int long long
#include "molecules.h"
using namespace std;
std::vector<int> find_subset(int l, int u, std::vector<int> w) {
multiset<pair<int,int>>ms;
int n=w.size();
for(int i=0;i<n;i++)ms.insert({w[i],i});
vector<int>ans;
while(l>0){
auto lb=ms.lower_bound({l,-1e18});
if(lb==ms.end()){
lb--;
if(lb==ms.begin())return {};
}
else {
pair<int,int>B=*lb;
ans.push_back(B.second);
u-=B.first;
if(u<0)return {};
break;
}
pair<int,int>A=*lb;
l-=A.first;
u-=A.first;
if(u<0)return {};
//cout<<l<<" "<<u;
//cout<<endl;
ans.push_back(A.second);
ms.erase(A);
}
return ans;
}/*
signed main(){
for(auto it:find_subset(14, 15, {5, 5,
6}))cout<<it<<" ";
}*/