# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
50193 | 2018-06-08T08:29:31 Z | hugo_pm | Detecting Molecules (IOI16_molecules) | C++14 | 0 ms | 0 KB |
#include <bits/stdc++.h> #pragma GCC diagnostic ignored "-Wunused-result" using namespace std; vector<int> solve(int l, int u, vector<int> w) { vector<pair<int, int>> rafin(w.size()); for (int i = 0; i < (int)(w.size()); ++i) rafin[i] = {w[i], i+1}; sort(rafin.begin(), rafin.end()); sort(w.begin(), w.end()); int somme = 0; int k = w.size() - 1; int i = k; while ((somme < l || somme > u) && (i >= 0 && k >= 0)) { if (somme < l) { somme += w[i]; --i; } else { somme -= w[k]; --k; } } if (somme < l || somme > u) return {}; ++i; vector<int> ans(k-i+1); for (int o = i; o <= k; ++o) ans[o-i] = rafin[o].second; return ans; }