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(n);
for(int i=0;i<n;i++) vec[i] = {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());
if(deq.empty() || cr == 0) exit(2);
deq.pop_back(); cs -= vec[--cr].first;
while(cr < n && cs < l) {
cs += vec[cr].first;
cs -= w[deq.front()];
deq.pop_front();
deq.emplace_back(vec[cr++].second);
}
if(cs < l) return {};
return vector<int>(deq.begin(), deq.end());
}
/*
int main() {
vector<int> arr = {342, 234, 235, 454, 345, 234, 464, 123, 134};
auto res = find_subset(400, 800, arr);
int sum = 0;
for(int e:res)sum += arr[e];
for(int i=0;i<res.size();i++) cout << res[i] << ' ';
cout << '\n' << sum ;
}*/
# | 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... |