이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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_front(); cs -= vec[0].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... |