# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
54136 | 2018-07-02T13:01:12 Z | WLZ | Detecting Molecules (IOI16_molecules) | C++17 | 0 ms | 0 KB |
#include "molecules.h" #include <iostream> #include <vector> #include <algorithm> #include <utility> using namespace std; vector<int> find_subset(int n, int l, int u, vector<int> w) { vector< pair<int, int> > v; for (int i = 0; i < n; i++) { v.emplace_back(w[i], i); } sort(v.begin(), v.end()); int i = 0, j = 0; long long cur = 0ll; vector<int> was(n, 0); int cnt = 0; for (;;) { while (i < n && cur < (long long) l) { was[v[i].second] = 1; cur += (long long) v[i++].first; cnt++; } while (j < n && cur > (long long) u) { was[v[j].second] = 0; cur -= (long long) v[j++].first; cnt--; } if (cur >= l && cur <= u) { vector<int> ans; for (int i = 0; i < n; i++) { if (was[i]) { ans.push_back(i); } } return ans; } if (i >= n || j >= n) { break; } } return {}; }