# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
491956 | franfill | 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>
#include "molecules.h"
using namespace std;
typedef long long ll;
typedef pair < ll , ll > ii;
std::vector<int> find_subset(int f, int u, std::vector<int> w)
{
vector < ii > ws;
for (int i = 0; i < w.size(); i++)
{
ws.push_back({w[i], i});
}
sort(ws.begin(), ws.end());
ll l = 0;
ll sum = ws[0].first;
for (ll r = 1; r <= w.size(); r++)
{
while(sum > u)
{
sum -= ws[l++].first;
}
if (sum >= f)
{
vector < ll > ans;
for (int i = l; i < r; i++)
{
ans.push_back(ws[i].second);
}
return ans;
}
if (r < w.size()) sum += ws[r].first;
}
return {};
}