# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
44839 | RayaBurong25_1 | Detecting Molecules (IOI16_molecules) | C++17 | 86 ms | 25872 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 "molecules.h"
#include <stdio.h>
#include <algorithm>
int compare(std::pair<long long, int> a, std::pair<long long, int> b)
{
return (a.first < b.first || (a.first == b.first && a.second < b.second));
}
std::vector<int> find_subset(int l, int u, std::vector<int> w) {
std::vector<std::pair<long long, int> > W;
std::vector<int> V;
int n = w.size(), i, j;
long long mn = 0, mx = 0;
for (i = 0; i < n; i++)
W.push_back({w[i], i});
std::sort(W.begin(), W.end(), compare);
for (i = 0; i < n; i++)
{
mn += W[i].first;
mx += W[n - 1 - i].first;
// printf("mn %d mx %d\n", mn, mx);
if ((l <= mx && mx <= u) || (l <= mn && mn <= u) || (mn <= l && u <= mx))
break;
}
if (i == n)
return V;
for (j = 0; j <= i; j++)
V.push_back(j);
while (mn < l)
{
if (V[i] == n - (j - i))
i--;
mn -= W[V[i]].first;
V[i] = n - (j - i);
mn += W[V[i]].first;
}
for (i = 0; i < V.size(); i++)
V[i] = W[V[i]].second;
return V;
}
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... |