이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "molecules.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<int> find_subset(int _l, int _u, vector<int> w) {
ll l = _l, u = _u;
int n = w.size();
if (n == 1) {
if (w[0] >= l && w[0] <= u)
return {1};
return {};
}
vector<int> idxs(n);
iota(idxs.begin(), idxs.end(), 0);
sort(idxs.begin(), idxs.end(), [&](int i, int j){ return w[i] < w[j]; });
vector<int> ans;
ll s = 0;
int small = w[idxs[0]];
int big = w[idxs.back()];
for (int _i = n-2; _i > 0; --_i) {
int i = idxs[_i];
if (s+w[i] >= l && s+w[i] <= u) {
ans.push_back(i+1);
s += w[i];
return ans;
}
if (s+w[i]+big < l) {
ans.push_back(i+1);
s += w[i];
} else if (s+w[i]+small <= u) {
s += w[i];
ans.push_back(i+1);
break;
}
}
if (s >= l && s <= u) return ans;
else if (s+small >= l && s+small <= u) {
ans.push_back(idxs[0]+1);
return ans;
} else if (s+big >= l && s+big <= u) {
ans.push_back(idxs.back()+1);
return ans;
} else if (s+small+big >= l && s+small+big <= u) {
ans.push_back(idxs[0]+1);
ans.push_back(idxs.back()+1);
return ans;
}
return {};
}
# | 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... |