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 <algorithm>
#include <set>
using namespace std;
#define pb push_back
#define pii pair<int, int>
#define f first
#define s second
#define ll long long
#define pll pair<ll, ll>
vector<int> find_subset(int l, int u, vector<int> w) {
int n = w.size();
vector<pll> v(n);
for (int i = 0; i < n; ++i) {
v[i].f = w[i];
v[i].s = i;
}
sort(v.begin(), v.end());
set<int> st;
ll sum = 0;
int k = 0;
for (int i = n-1; i >= 0; --i){
sum += v[i].f;
k = i;
st.insert(v[i].s);
if (sum >= l) break;
}
if (sum < l){
vector<int> ans;
return ans;
} else if (sum >= l && sum <= u){
vector<int> ans;
for (auto x : st){
ans.pb(x);
}
return ans;
}
for (int i = 0; i < min(k, (n+1)/2); ++i){
ll dif = v[n-i-1].f - v[i].f;
sum -= dif;
st.erase(v[n-i-1].s);
st.insert(v[i].s);
if (sum <= u) break;
}
if (sum > u){
return vector<int>(0);
} else{
vector<int> ans;
for (auto x : st){
ans.pb(x);
}
return ans;
}
}
# | 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... |