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;
const int MAXN = 5e5 + 3e2;
pair<int, int> a[MAXN];
vector<int> find_subset(int l, int u, vector<int> w) {
int n = w.size();
for (int i = 0; i < n; i++){
a[i + 1] = make_pair(w[i], i);
if (l <= w[i] && w[i] <= u){
return {i};
}
}
sort(a + 1, a + n + 1);
vector<int> ans;
int sum = 0;
for (int i = n; i >= 1; i--){
ans.push_back(a[i].second);
sum += a[i].first;
if (l <= sum && sum <= u) return ans;
if (sum > l) break;
int pos = lower_bound(a + 1, a + n + 1, make_pair(l - sum, 0)) - begin(a);
if (pos < i){
int x = a[pos].first;
if (sum + x <= u){
ans.push_back(a[pos].second);
return ans;
}
}
}
ans.clear();
sum = 0;
for (int i = 1; i <= n; i++){
ans.push_back(a[i].second);
sum += a[i].first;
if (l <= sum && sum <= u) return ans;
if (sum > l) break;
int pos = upper_bound(a + 1, a + n + 1, make_pair(l - sum, -1)) - begin(a) - 1;
if (pos > i && pos <= n){
int x = a[pos].first;
if (sum + x <= u){
ans.push_back(a[pos].second);
return ans;
}
}
}
return vector<int>(0);
}
# | 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... |