# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1078409 | 2024-08-27T16:45:53 Z | DrAymeinstein | Detecting Molecules (IOI16_molecules) | C++17 | 0 ms | 0 KB |
#include <iostream> #include <vector> #include <algorithm> #include <cmath> #include "molecules.h" using namespace std; using namespace std; static vector<int> find_subset(int l, int u, vector<int> w) { vector<pair<int, int>> vec; int n = w.size(); for (int i = 0; i < n; i++) { vec.push_back({ w[i], i }); // vec = {weight, index) } // Sort by w[i] sort(vec.begin(), vec.end()); int left = 0, right = 0; long long currentSum = vec[0].first; bool found = false; while (true) { if (currentSum >= l && currentSum <= u) { found = true; break; } if (currentSum < l && right + 1 < n) { right++; currentSum += vec[right].first; } else if (currentSum > u && left < right) { currentSum -= vec[left].first; left++; } else { break; } } vector<int> result; if (found) { for (int i = left; i <= right; i++) { result.push_back(vec[i].second); } } return result; }