# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
416664 | 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;
signed find_subset(signed l, signed u, signed *w, signed n, signed *result)
{
vector<pair<int, int>> arr;
vector<int> prefarr(n + 1);
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[i - a] = arr[i].second;
return b - a;
}
}
return 0;
}