# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1132190 | lopkus | Detecting Molecules (IOI16_molecules) | C++20 | 0 ms | 320 KiB |
#include <bits/stdc++.h>
#include "molecules.h"
using namespace std;
std::vector<int> find_subset(int l, int u, std::vector<int> w) {
sort(w.begin(), w.end());
int n = w.size();
for(int i = 0; i < n; i++) {
if(w[i] >= l && w[i] <= u) {
return {i};
}
}
int idx = - 1;
for(int i = 0; i < n; i++) {
if(w[i] < l) {
idx = i;
}
}
if(idx == - 1) {
return {};
}
set<int> s;
s.insert(w[idx]);
for(int i = idx; i >= 0; i--) {
if(u - l >= w[idx] - w[i]) {
s.insert(w[i]);
}
}
vector<int> ans;
while(l > 0) {
auto it = s.lower_bound(l);
if(it != s.end() && *it <= u) {
ans.push_back(*it);
l -= *it;
u -= *it;
s.erase(it);
continue;
}
it--;
if(it != s.end()) {
ans.push_back(*it);
l -= *it;
u -= *it;
s.erase(it);
}
else {
return {};
}
}
return ans;
}
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... |