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 <bits/stdc++.h>
#include "molecules.h"
using namespace std;
vector<int> find_subset(int l, int u, vector<int> w) {
int n = w.size();
if(accumulate(w.begin(), w.end(), 0ll) < l) return {};
int cr=0;
long long cs = 0;
vector<pair<int, int>> vec;
for(int i=0;i<n;i++) vec.emplace_back(w[i], i);
sort(vec.begin(), vec.end());
deque<int> deq;
while(cr < n && cs < l) {
cs += vec[cr].first;
deq.emplace_back(vec[cr++].second);
}
if(cs <= u) return vector<int>(deq.begin(), deq.end());
deq.pop_back(); cs -= vec[--cr].first;
while(cr < n && cs < l) {
cs += vec[cr].first;
cs -= w[deq.front()];
deq.emplace_back(vec[cr++].second);
}
if(cs < l) return {};
return vector<int>(deq.begin(), deq.end());
}
/*
int main() {
vector<int> arr = {6, 8, 8, 7};
auto res = find_subset(15, 17, arr);
for(int i=0;i<res.size();i++) cout << res[i] << ' ';
}*/
# | 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... |