Submission #602638

#TimeUsernameProblemLanguageResultExecution timeMemory
602638georgievskiyDetecting Molecules (IOI16_molecules)C++17
100 / 100
49 ms5544 KiB
#include "molecules.h" #include <bits/stdc++.h> using namespace std; using ll = long long ; std::vector<int> find_subset(int l, int u, std::vector<int> w) { int n = w.size(); vector<pair<int,int>> t(n); for (int i = 0; i < n; i++) t[i] = {w[i], i}; sort(t.begin(), t.end()); ll s = 0; if (u < t[0].first) return vector<int>(); for (int len = 1; len <= n; len++) { s += t[len-1].first; if (s >= l && s <= u) { vector<int> ans; for (int i = 0; i < len; i++) ans.push_back(t[i].second); return ans; } if (s > u) { s -= t[len-1].first; len--; for (int i = len; i < n; i++) { s += t[i].first - t[i - len].first; if (s >= l && s <= u) { vector<int> ans; for (int j = i - len + 1; j <= i; j++) ans.push_back(t[j].second); return ans; } } break; } } return vector<int>(); }
#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...