# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
299412 | 2020-09-14T21:10:17 Z | sandoval | Detecting Molecules (IOI16_molecules) | C++11 | 0 ms | 0 KB |
#include <bits/stdc++.h> using namespace std; using ii = pair<int,int>; using ll = long long; int find_subset(int l, int u, int w[], int n, int result[]) { if (l > u) return 0; map<ll,int> m; m[0] = 0; ll sum = 0; for (int i = 1; i <= (int)n; ++i) { sum += w[i-1]; ll k = sum-l; auto it = m.upper_bound(k); if (it != m.begin()) { it = prev(it); ll o = sum-it->first; assert(o >= l); if (o <= u) { const int len = i-it->second; for (int j = i-len+1, c = 0; j <= i; ++j, ++c) { result[c] = j-1; } return len; } } m[sum] = i; } return 0; }