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<bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> pii;
constexpr int maxn = 2e5 + 5;
ll pref[maxn] = { 0 }, suff[maxn] = { 0 };
std::vector<int> find_subset(int l, int u, std::vector<int> w) {
sort(w.begin(), w.end());
pref[0] = w[0];
for (size_t i = 1; i < w.size(); i++) pref[i] = pref[i - 1] + w[i];
suff[0] = w.back();
for (size_t i = 1; i < w.size(); i++) suff[i] = suff[i - 1] + w[w.size() - i - 1];
int n = w.size();
int len = -1;
for (int i = 0; i < n; i++)
{
if (pref[i] <= u && suff[i] >= l)
{
len = i + 1;
break;
}
}
if (len == -1)
{
// Impossible
return vector <int>();
}
ll val = suff[len - 1];
vector <int> output(w.end() - len, w.end());
int i = 0;
while (val > u)
{
val += w[i] - w[n - i - 1];
swap(output[len - i - 1], w[i]);
}
return output;
}
# | 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... |