# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
265744 | 2020-08-15T04:36:27 Z | amalla | Detecting Molecules (IOI16_molecules) | C++17 | 0 ms | 0 KB |
#include "molecules.h" #include<bits/stdc++.h> using namespace std; #define ll long long vector<int> find_subset(int l, int u, vector<int> w) { int N = w.size(); pair<int,int> A[N-1]; for (int i = 0; i<N; ++i) { A[i].first = w[i]; A[i].second = i; } sort(A, A); ll prefix[N]; prefix[0] = 0; for (int i = 1; i<=N; ++i) prefix[i] = prefix[i-1] + A[i-1].first; int i = 0, j = 1; while (true) { if (prefix[j]-prefix[i]<l) { ++j; if (j>N) break; } else if (prefix[j]-prefix[i]>u) { ++i; while (i>=j) { ++j; if (j>N) break; } } else { vector<int> Ans(j-i); int k = 0; while(i<=j) { ++i; Ans[k] = A[i].second; } return Ans; } } } return {0}; }