# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
900086 | mannshah1211 | 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 int long long
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(), x.end()
vector<int> find_subset(int l, int u, vector<int> w) {
if (accumulate(all(w), 0LL) < l) {
return {};
}
vector<pair<int, int>> indices;
for (int i = 0; i < w.size(); i++) {
indices.pb({w[i], i});
}
if (indices[0].f > u) {
return {};
}
sort(all(indices));
int cursum = 0, longest = 0;
for (int i = 0; i < indices.size(); i++) {
cursum += indices[i].f;
if (cursum >= l) {
cursum -= indices[i].f, longest = i;
break;
}
}
for (int i = longest; i < indices.size(); i++) {
cursum += indices[i].f;
cursum -= indices[i - longest].f;
if (cursum >= l && cursum <= u) {
vector<int> answer;
for (int j = i; j >= i - longest + 1; j--) {
answer.pb(indices[j].s);
}
return answer;
}
}
return {};
}