# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
700960 | abczz | 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 <iostream>
#include <algorithm>
#define ll long long
using namespace std;
ll n, l, r, ps[200000];
pair <ll, ll> a[200000];
int main() {
cin >> n >> l >> r;
for (int i=0; i<n; ++i) {
cin >> a[i].first;
a[i].second = i;
}
sort(a, a+n, [](auto a, auto b) {
return a.first < b.first;
});
for (int i=0; i<n; ++i) {
if (i == 0) ps[i] = a[i].first;
else ps[i] = ps[i-1] + a[i].first;
}
for (int i=0; i<n; ++i) {
if (ps[i] >= l && ps[i] <= r) {
cout << i+1 << endl;
for (int j=0; j<=i; ++j) {
cout << a[j].second << " ";
}
return 0;
}
}
int i=0, j=0;
while (max(i, j) < n) {
if (ps[i]-ps[j] >= l && ps[i]-ps[j] <= r) {
cout << i-j << endl;
for (int k=j+1; k<=i; ++k) {
cout << a[k].second << " ";
}
return 0;
}
else if (ps[i]-ps[j] > r) ++j;
else ++i;
}
cout << 0 << endl;
}