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
using namespace std;
std::vector<int> find_subset(int l, int u, std::vector<int> w) {
ll s = 0, L = l, R = u;
int n = w.size();
vector < int > ans;
vector < pair < int, int > > a;
for(int i = 0; i < n; i++) a.push_back({w[i], i});
sort(a.begin(), a.end());
int j = 0;
for(int i = 0; i < n; i++) s += a[i].first;
for(int i = 0; i < n; i++){
while(j <= i) s -= a[j].first, j++;
s += a[i].first;
while(s > R && j < n) s -= a[j].first, j++;
if(L <= s && s <= R){
for(int it = 0; it <= i; it++) ans.push_back(a[j].second);
for(int it = max(j, i + 1); it < n; it++) ans.push_back(a[j].second);
return ans;
}
}
int it = 1000;
while(it--){
s = 0;
random_shuffle(a.begin(), a.end());
ans.clear();
for(int i = 0; i < n; i++){
s += a[i].first;
if(L <= s && s <= R){
for(int j = 0; j <= i; j++) ans.push_back(a[j].second);
return ans;
}
}
}
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... |