#include <bits/stdc++.h>
using namespace std;
// #define LOCAL
#ifndef LOCAL
#include "molecules.h"
#endif
using ll = long long;
std::vector<int> find_subset(int l, int u, std::vector<int> w) {
int N = (int)w.size();
vector<array<int, 2>> a;
for (int i = 0; i < N; ++i) {
a.push_back({w[i], i});
}
sort(begin(a), end(a));
int left = 0;
ll sum = 0;
vector<int> res;
for (int i = 0; i < N; ++i) {
sum += a[i][0];
while (sum > u) {
sum -= a[left][0];
left++;
}
if (sum >= l && sum <= u) {
for (int j = left; j <= i; ++j) {
res.push_back(a[j][1]);
}
sort(begin(res), end(res));
return res;
}
}
return {};
}
#ifdef LOCAL
/*
4 15 17
6 8 8 7
4 14 15
5 5 6 6
4 10 20
15 17 16 18
*/
#include <cstdio>
#include <vector>
#include <cassert>
int main() {
int n, l, u;
assert(3 == scanf("%d %d %d", &n, &l, &u));
std::vector<int> w(n);
for (int i = 0; i < n; i++)
assert(1 == scanf("%d", &w[i]));
std::vector<int> result = find_subset(l, u, w);
printf("%d\n", (int)result.size());
for (int i = 0; i < (int)result.size(); i++)
printf("%d%c", result[i], " \n"[i == (int)result.size() - 1]);
}
#endif
Compilation message (stderr)
molecules.h:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
molecules_c.h:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
# | 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... |