# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1056863 | fv3 | 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 "molecules.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define value first
#define index second
vector<int> find_subset(int L, int R, vector<int> w_)
{
const int N = w_.size();
vector<pair<int, int>> W(N);
for (int i = 0; i < N; i++)
W[i] = {w_[i], i};
sort(W.begin(), W.end());
ll sum = 0;
for (int i = 0; i < N; i++)
{
sum += W[i].value;
}
if (sum < L || W[0].value > R)
{
return {};
}
if (sum >= L && sum <= R)
{
vector<int> res(N);
iota(res.begin(), res.end(), 0);
return res;
}
if (W[0].value >= L && W[0].value <= R)
{
return {0};
}
int mx_cnt = 0;
sum = 0;
while (sum + W[mx_cnt].value <= R)
{
sum += W[mx_cnt].value;
mx_cnt++;
}
int mn_cnt = 1;
int back = N - 1;
sum = 0;
while (sum + W[back].value < L)
{
sum += W[back--].value;
mn_cnt++;
}
if (mn_cnt > mx_cnt)
return {};
vector<int> res(mn_cnt);
sum = 0;
for (int i = 0; i < mn_cnt; i++)
{
res[i] = W[i].index;
sum += W[i].value;
}
int l = 0;
int r = N - 1;
while (sum < L)
{
sum += W[r].value - W[l].value;
res[l++] = W[r--].index;
}
return res;
}
#include "grader.cpp"