# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
685711 | Bliznetc | 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>
using namespace std;
#define pb push_back
#define sz size()
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define int long long
typedef pair < int, int > pii;
typedef vector < int > vi;
typedef vector < vi > vvi;
std::vector<int> find_subset(int l, int u, std::vector<int> w)
{
int n = w.size();
pair<int,int> a[n + 7];
int sum = 0;
for (int i = 1; i <= n; i++) {
a[i] = {w[i - 1], i};
sum += a[i].F;
}
sort (a + 1, a + n + 1);
if (sum < l) {
return vector<int> (0);
}
int r = u;
if (a[1].F > u) {
return vector<int>(0);
}
int cur = 0;
vector<int> result;
int j = 1;
int i = 1;
deque <int> d;
while (j <= n || i <= n) {
if (cur < l) {
cur += a[j].F;
d.pb(a[j].S);
j++;
}
if (cur > r) {
cur -= a[i].F;
d.pop_front();
i++;
}
if (cur >= l && cur <= r) {
break;
}
}
if (cur >= l && cur <= r) {
return vector<int> (all(d));
}
return vector<int> (0);
}