# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
397135 | ak2006 | 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.
#include <bits/stdc++.h>
#include "molecules.h"
using namespace std;
#define ll long long
#define vi vector<int>
#define vvi vector<vi>
vi find_subset(int l,int u,vi w)
{
int n = w.size();
vvi a(n,vi(2));
for (int i = 0;i<n;i++)a[i][0] = w[i],a[i][1] = i;
sort(a.begin(),a.end());
ll sum = a[0][0],l = 0,r = 1;
while (r <= n){
if (sum >= mn && sum <= mx)break;
if (sum > mx){sum -= a[l][0];l++;}
else {if (r == n)break;sum += a[r][0];r++;}
if (sum >= mn && sum <= mx)break;
}
if (sum >= mn && sum <= mx){
vi ret;
for (int i = l;i<r;i++)ret.push_back(a[i][1]);
return ret;
}
return {};
}