# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
416674 | schse | 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>
#define int long long
//#include "molecules grader.cpp"
using namespace std;
std::vector<int> find_subset(int l, int u, std::vector<int> w) {
signed n= w.size();
vector<pair<int, int>> arr;
vector<int> prefarr(n + 1),result;
for (int i = 0; i < n; i++)
{
arr.push_back({w[i], i});
}
sort(arr.begin(), arr.end());
prefarr[0] = 0;
for (int i = 0; i < n; i++)
prefarr[i + 1] = prefarr[i] + arr[i].first;
int a = 0, b = 0,tmp;
bool change=true;
while (change)
{
change=false;
while (l > prefarr[b] - prefarr[a]&&b!=arr.size())
b++,
change=true;
while (u < prefarr[b] - prefarr[a]&&a<b)
a++,
change=true;
if (l <= prefarr[b] - prefarr[a] && prefarr[b] - prefarr[a] <= u)
{
for (int i = a; i < b; i++)
result.push_back(arr[i].second);
return result;
}
}
return std::vector<int>(0);
}