# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
404105 | luisgalan | Detecting Molecules (IOI16_molecules) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#include "molecules.h"
using namespace std;
typedef long long int ll;
#define debug(x) cerr << #x << " = " << (x) << endl
vector<int> find_subset(int l, int u, vector<int> w) {
int n = w.size();
vector<pair<int, int>> arr(n);
for (int i = 0; i < n; i++) {
arr[i] = { w[i], i };
}
sort(arr.begin(), arr.end());
vector<ll> presum(n+1);
for (int i = 0; i < n; i++) {
presum[i + 1] = presum[i] + arr[i].first;
}
vector<int> ans;
for (int k = 1; k <= n; k++) {
int L = 0;
int R = n - k + 1;
while (L < R) {
int m = (L + R) / 2;
ll sum = presum[m + k] - presum[m];
if (sum < l) {
L = m + 1;
} else if (sum > u) {
R = m;
} else {
debug(sum);
for (int j = i; j < i + k; j++) {
ans.push_back(arr[j].second);
}
break;
}
}
if (!ans.empty()) break;
}
return ans;
}