# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
651353 | pauloamed | 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<bits/stdc++.h>
#include "molecules.h"
using namespace std;
vector<int> find_subset(int l, int u, vector<int> w){
int n = w.size();
vector<pair<int,int>> W;
for(int i = 0; i < n; ++i){
W.push_back({w[i], i});
}
sort(W.begin(), W.end());
vector<int> ans;
for(int i = 0; i < n; ++i){
int mini = W[i].first;
int id_mini = W[i].second;
int maxi = W.back().first;
int id_maxi = W.back().second;
if(mini > u) return {};
else if(mini >= l){
ans.push_back(id_mini);
return ans;
}else{
// mini ta a esquerda
// maxi ta dentro ou a esquerda
assert(maxi <= u);
ans.push_back(id_maxi);
if(maxi >= l){ // maxi ta dentro
return ans;
}else{ // maxi ta a esquerda
l -= maxi;
u -= maxi;
}
W.pop_back();
}
}
if(0 >= l && 0 <= u) return ans;
else return {};
}
int32_t main(){
auto ret = find_subset(15, 17, {6,8,8,7});
for(auto x : ret) cout << x << " ";
cout << "\n";
ret = find_subset(14, 15, {5, 5, 6, 6});
for(auto x : ret) cout << x << " ";
cout << "\n";
ret = find_subset(10, 20, {15, 17, 16, 18});
for(auto x : ret) cout << x << " ";
cout << "\n";
}