Submission #1003251

#TimeUsernameProblemLanguageResultExecution timeMemory
1003251toast12Detecting Molecules (IOI16_molecules)C++14
31 / 100
3 ms952 KiB
#include "molecules.h" #include <vector> #include <algorithm> using namespace std; vector<int> find_subset(int l, int u, vector<int> w) { int n = (int)w.size(); vector<pair<int, int>> a; for (int i = 0; i < n; i++) { a.push_back({w[i], i}); } sort(a.begin(), a.end()); int left = 0, right = 0; int cur_sum = a[0].first; bool poss = false; while (right < n) { while (cur_sum < l) { right++; cur_sum += a[right].first; } while (cur_sum > u) { cur_sum -= a[left].first; left++; if (right < left) { right = left; cur_sum = a[left].first; } } if (cur_sum >= l && cur_sum <= u) { poss = true; break; } } vector<int> answer(0); if (poss) { for (int i = left; i <= right; i++) { answer.push_back(a[i].second); } } return answer; }
#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...