# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1226959 | lacito | Detecting Molecules (IOI16_molecules) | C++20 | 34 ms | 3656 KiB |
#include <bits/stdc++.h>
#include "molecules.h"
using namespace std;
std::vector<int> find_subset(int l, int u, std::vector<int> w) {
int n = w.size();
vector<pair<int, int>> items(n);
for (int i = 0; i < n; i++) {
items[i].first = w[i];
items[i].second = i;
}
sort(items.begin(), items.end());
long long small = 0, big = 0;
for (int k = 1; k <= n; k++) {
small += items[k-1].first;
big += items[n-k].first;
if (small > u || big < l) continue;
long long sum = small;
if (l <= sum && sum <= u) {
vector<int> solution;
for (int j = 0; j < k; j++) {
solution.push_back(items[j].second);
}
return solution;
}
for (int i = k; i < n; i++) {
sum += items[i].first;
sum -= items[i-k].first;
if (l <= sum && sum <= u) {
vector<int> solution;
for (int j = i - k + 1; j <= i; j++) {
solution.push_back(items[j].second);
}
return solution;
}
}
}
return std::vector<int>(0);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |