#P6169. [IOI 2016] molecules
[IOI 2016] molecules
Description
Peter works at a company that has built a machine to detect molecules. The weight of each molecule is a positive integer. The detection range of the machine is , where both and are positive integers. The machine can detect a set of molecules if and only if this set contains a subset whose total weight lies within the detection range.
Consider molecules with weights . If there exists a set of indices (and all indices in the set are distinct) such that , then the detection succeeds.
Due to the details of the machine, the difference between and is guaranteed to be at least the difference between the heaviest and the lightest molecule, i.e. , where and .
Your task is to write a program that finds a subset whose total weight lies within the detection range, or determines that no such subset exists.
Sample 1
4 15 17
6 8 8 7
In this example, we have four molecules with weights and . The machine can detect a subset whose total weight is between and (including and ). Note that . The sum of the weights of molecule and molecule is , so the output should be
2
1 3
Other possible correct answers are
2
1 2
()
and
2
2 3
().
Sample 2
4 14 15
5 5 6 6
In this example, we have four molecules with weights and . We want to find a subset whose total weight is between and (including and ). Note that . Since there is no subset whose total weight is between and , output 0.
Input Format
-
The first line: integers and .
-
The second line: integers: .
Output Format
If there is a subset that satisfies the condition:
-
The first line: output the size of the subset .
-
The second line: integers, the indices of the molecules in a valid subset.
If not, output 0.
1 10 12
9
0
2 5 10
4 2
2
0 1
Hint
Constraints: for of the data, , , and .
Translated by ChatGPT 5
京公网安备 11011102002149号