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>
#define ll long long
#define st first
#define nd second
using namespace std;
vector<int> find_subset(int L, int U, vector<int> W) {
ll l = L;
ll u = U;
vector<pair<ll, int>> w;
for(int i=0; i<(int)W.size(); ++i) {
w.push_back({W[i], i});
}
sort(w.begin(), w.end());
ll sum=0;
int n = w.size(), i = 0;
vector<int> ans;
while(i<n && sum+w[i].st<=u) {
sum+=w[i].st;
ans.push_back(i);
i++;
}
i = n-1;
vector<int> added;
while(ans.size() && sum+w[i].st-w[ans.back()].st<=u) {
sum+=w[i].st-w[ans.back()].st;
added.push_back(i);
i--;
ans.pop_back();
}
if(sum>=l && sum<=u) {
for(int k: added) {
ans.push_back(k);
}
for(int &k: ans) {
k=w[k].nd;
}
return ans;
}
else {
return vector<int>();
}
}
# | 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... |