Petr is working for a company that has built a machine for detecting molecules. Each molecule has a positive integer weight. The machine has a detection range
Formally, consider
Due to specifics of the machine, the gap between
Your task is to write a program which either finds any one subset of molecules with total weight within the detection range, or determines that there is no such subset.
Implementation details
You should implement one function (method):
int find_subset(int l, int u, int w[], int n, int result[])
l
andu
: the endpoints of the detection range,w
: weights of the molecules,n
: the number of elements in (i.e., the number of molecules),result
: an array of integers. The method should write the indices of molecules that form any one such subset to the first cells of arrayresult
. If there are several correct answers, write any of them.- The function should return the value of
. If the required subset does not exist, the function should not write anything to theresult
array and it should return0
.
Your program may write the indices into the result
array in any order.
Sample 1
find_subset(15, 17, {6, 8, 8, 7}, 4, result)
In this example we have four molecules with weights result
array can contain {1, 3}
and the function should return 2
. Other possible correct answers are {1, 2}
[2, 3]
Sample 2
find_subset(14, 15, {5, 5, 6, 6}, 4, result)
In this example we have four molecules with weights 0
.
Sample 3
find_subset(10, 20, {15, 17, 16, 18}, 4, result)
In this example we have four molecules with weights {0}
, {1}
, {2}
and {3}
.
Subtasks
- (9 points):
, all are equal. - (10 points):
and . - (12 points):
and . - (15 points):
and . - (23 points):
and . - (31 points):
and .
Comments