# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
636094 | nehasane | Detecting Molecules (IOI16_molecules) | C++14 | 0 ms | 0 KiB |
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 "molecules.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> find_subset(int l, int u, vector<int> w) {
vector <int> ans;
int n = w.size(), p = 0;
vector <pair <int, int>> wt(n);
for (int i = 0; i < n; i++)
wt[i] = {w[i], i};
sort(wt.begin(), wt.end());
long long sum = 0;
for (int i = 0; i < n; i++) {
if (sum + wt[i].first >= l) {
p = i;
break;
}
sum += wt[i].first;
ans.push_back(wt[i].second);
}
for (int i = p; i < n; i++) {
if (sum + wt[i].first >= l && sum + wt[i].first <= u) {
ans.push_back(wt[i].second);
sum += wt[i].first;
break;
}
}
if (sum < l)
ans.clear();
return ans;
}
int main() {
int n, l, u;
cin >> n >> l >> u;
vector <int> w(n);
for (int i = 0; i < n; i++)
cin >> w[i];
vector <int> ans = find_subset(l, u, w);
for (auto i : ans)
cout << i << ' ';
cout << '\n';
}