# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
685699 | 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 <bits/stdc++.h>
#include "molecules.h"
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC target("avx2")
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;
vi find_subset(int l, int u, vi w) {
int n = w.sz;
pii 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 {};
}
int r = u;
if (a[1].F > u) {
return {};
}
int cur = 0;
vi result;
for (int i = 1; i <= n; i++) {
if (cur + a[i].F >= l) {
if (cur + a[i].F <= r) {
cur += a[i].F;
result.pb(a[i].S);
}
break;
}
cur += a[i].F;
result.pb(a[i].S);
}
if (cur < l) {
for (int i = 0; i < (int)result.size(); i++) {
if (cur - a[i + 1].F + a[n].F <= r) {
result[i] = a[n].S;
break;
}
}
}
if (cur >= l && cur <= r) {
return result;
}
return {};
}