# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1078392 | sqrteipi | 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 <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main(){
int n, l, r;
cin >> n >> l >> r;
vector<pair<int, int>> vec;
for (int i=0; i<n; i++) {
int k;
cin >> k;
vec.push_back({k, i});
}
sort(vec.begin(), vec.end());
int mi = 0, ma = 0, li = 0, ri = n - 1;
while (li < n) {
mi += vec[li].first, ma += vec[ri].first;
if (l <= mi && mi <= r) {
cout << li + 1 << "\n";
for (int i=0; i<=li; i++) cout << vec[i].second << " ";
return 0;
}
if (l <= ma && ma <= r) {
cout << li + 1 << "\n";
for (int i=ri; i<n; i++) cout << vec[i].second << " ";
return 0;
}
if (mi <= l && r <= ma) {
int sum = mi - vec[li].first;
for (int i=li; i<n; i++) {
sum += vec[i].first;
if (l <= sum && sum <= r) {
cout << li + 1 << "\n";
for (int j=i-li; j<=i; j++) cout << vec[j].second << " ";
return 0;
}
sum -= vec[i-li].first;
}
}
li++, ri--;
}
cout << 0;
}