# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
987277 | normankr07 | 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>
using namespace std;
using ll = long long;
#include "molecules.h"
std::vector<int> find_subset(int l, int u, std::vector<int> w)
{
// for (int i = 1; i <= n; i++)
// {
// if (l <= w[i - 1] && w[i - 1] <= u)
// {
// return vector<int>(i);
// }
// }
vector<pair<int, int>> ww;
ll sum = 0;
for (int i = 0; i < n; i++)
{
sum += w[i];
ww.push_back(make_pair(w[i], i));
}
sort(ww.begin(), ww.end());
vector<int> id;
for (int i = n - 1, j = n; i < j && i >= -1;)
{
while (sum > u && i >= 0)
{
sum -= ww[i].first;
i--;
}
if (l <= sum && sum <= u)
{
for (int p = 0; p <= i; p++)
id.push_back(ww[p].second);
for (int p = j; p < n; p++)
id.push_back(ww[p].second);
return id;
}
j--;
sum += ww[j].first;
}
return vector<int>();
}