# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1088548 | 2024-09-14T15:20:03 Z | LucasLe | Detecting Molecules (IOI16_molecules) | C++17 | 0 ms | 0 KB |
#include "molecules.h" #include <bits/stdc++.h> #define int long long using namespace std; const long long INF = 1e15; vector<int> find_subset(int l, int u, vector<int> w) { vector<pair<long long, int>> v; int n = (int)w.size(); for (int i = 0; i < n; ++i) v.push_back({w[i], i}); v.push_back({INF, n}); sort(v.begin(), v.end()); long long pref = 0, suff = 0; for (int i = 0; i < n; ++i) { pref += v[i].first; suff += v[n - 1 - i].first; if (pref <= u && suff >= l) { vector<int> res; for (int j = i; j < n; ++j) { if (pref >= l) { for (int k = j - i; k <= j; ++k) res.push_back(v[k].second); return res; } pref += v[j + 1].first - v[j - i].first; } } } return vector<int>(); }