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>
using namespace std;
#define ll long long
#define ar array
vector<int> find_subset(int l, int r, vector<int> w) {
int n = w.size();
vector<pair<int, int>> v(n);
for (int i = 0; i < n; ++i) {
v[i].first = w[i];
v[i].second = i;
}
sort(v.begin(), v.end());
if (accumulate(w.begin(), w.end(), 0ll) < l) return {};
ll cur = 0;
int ind = 0;
for (; cur < l; ++ind) cur += v[ind].first;
cur -= v[--ind].first;
vector<int> d(ind);
iota(d.begin(), d.end(), 0);
for (int i = ind - 1; i >= 0 && cur < l; --i) {
cur += v[n + i - ind].first - v[i].first;
d[i] = n + i - ind;
if (cur >= l) break;
}
if (cur < l) return {};
for (int& i : d) i = v[i].second;
return d;
}
/*int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int l = 15, r = 17;
vector<int> w = {6, 8, 8, 7};
vector<int> ans = find_subset(l, r, w);
cout << ans.size() << "\n";
for (int i : ans) cout << i << " ";
return 0;
}*/
# | 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... |