Submission #578358

#TimeUsernameProblemLanguageResultExecution timeMemory
578358islingrDetecting Molecules (IOI16_molecules)C++17
100 / 100
77 ms2644 KiB
#include "molecules.h" #include <algorithm> #include <cassert> #include <numeric> using i64 = int64_t; std::vector<int> find_subset(int l, int u, std::vector<int> w) { int n = w.size(); std::vector<int> ord(n); std::iota(ord.begin(), ord.end(), 0); std::sort(ord.begin(), ord.end(), [&](int x, int y) { return w[x] < w[y]; }); std::sort(w.begin(), w.end()); int k = 1; for (i64 mn = 0, mx = 0; k <= n; ++k) { mn += w[k - 1]; mx += w[n - k]; if (l <= mx && mn <= u) break; } if (k > n) return {}; auto cur = std::accumulate(w.begin(), w.begin() + k, i64(0)); for (int i = 0; i <= n - k; ++i) { if (l <= cur && cur <= u) return {ord.begin() + i, ord.begin() + i + k}; cur -= w[i]; cur += w[i + k]; } assert(false); return {}; }
#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...