Submission #592918

#TimeUsernameProblemLanguageResultExecution timeMemory
592918MahtimursuDetecting Molecules (IOI16_molecules)C++17
100 / 100
51 ms10288 KiB
#include "molecules.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; vector<int> find_subset(int l, int u, vector<int> w) { int n = w.size(); vector<pair<ll, int>> v(n); for (int i = 0; i < n; ++i) v[i] = {w[i], i}; sort(v.begin(), v.end()); vector<ll> pref(n), suf(n); for (int i = 0; i < n; ++i) { pref[i] = v[i].first; if (i != 0) pref[i] += pref[i - 1]; } for (int i = n - 1; i >= 0; --i) { suf[i] = v[i].first; if (i != n - 1) suf[i] += suf[i + 1]; } // Find max k for which pref[k] <= u int k = 0; for (; k < n; ++k) { if (pref[k] > u) { k--; break; } } if (k == n) k--; if (k == -1 || suf[n - k - 1] < l) return vector<int>(0); int left = 0; int right = k; ll cs = pref[k]; vector<int> ans; while (true) { if (cs >= l && cs <= u) { for (int i = left; i <= right; ++i) { ans.push_back(v[i].second); } break; } if (right == n - 1) break; cs -= v[left++].first; cs += v[++right].first; } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...