# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
700960 | abczz | Detecting Molecules (IOI16_molecules) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}