# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1115280 | Zflop | 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.
#pragma once
#include <bits/stdc++.h>
#include <vector>
using namespace std;
const int NMAX = (int)1e3 * 2;
std::vector<int> find_subset(int l, int u, std::vector<int> w) {
vector<pair<int,int>>p;
for (int i = 0; i < w.size();++i)
p.push_back({w[i],i});
sort(p.begin(),p.end());
set<pair<int,int>>m;
vector<int>v1;
int s = 0;
int i = w.size() - 1;
for (; i >= 0 && s <= u;--i) {
if (s >= l && s <= u) return v1;
m.insert(p[i]);
v1.push_back(p[i].second);
s += p[i].first;
}
if (s < l) return {};
if (s <= u && s >= l) return v1;
int j = i;
i = 0;
while (i <= j) {
auto a = *m.begin();
s -= a.first;
s += p[i].first;
m.erase(a);
m.insert(p[i]);
if (s <= u && s >= l) {
vector<int>v;
while (m.size()) {
auto b = *m.begin();
v.push_back(b.second);
m.erase(b);
}
return v;
}
++i;
}
while (s > u) {
auto a = *m.begin();
m.erase(m.begin());
s -= a.first;
}
vector<int>ceva;
while (m.size()) {
ceva.insert(*m.begin().second);
m.erase(m.begin());
}
if (s >= l) return ceva;
return {};
}