# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1223473 | lfe | Detecting Molecules (IOI16_molecules) | C++20 | 34 ms | 4276 KiB |
#include "molecules.h"
#include <vector>
#include <algorithm>
#include <queue>
using ll = long long;
using namespace std;
vector<int> qtov(queue<int>& q) {
vector<int> ut;
while (!q.empty()) {
ut.push_back(q.front());
q.pop();
}
return ut;
}
vector<int> find_subset(int l, int u, vector<int> w) {
int n = w.size();
vector<pair<int,int>> vekter;
for (int i = 0; i < n; i++) {
vekter.emplace_back(w[i], i);
}
sort(vekter.begin(), vekter.end());
int k = 0;
ll tot = 0;
queue<int> ind;
while (tot < l && k < n) {
tot += (ll) vekter[n-1-k].first;
ind.push(vekter[n-1-k].second);
k++;
}
if (tot <= u && tot >= l) return qtov(ind);
else if (tot < l) return vector<int>(0);
for (int i = 0; i < k; i++) {
tot -= w[ind.front()];
tot += vekter[i].first;
ind.pop();
ind.push(vekter[i].second);
if (tot <= u && tot >= l) return qtov(ind);
}
return 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... |