Oof! You've been coding the whole day and you even had no time for Stack Exchange!
Now, you just want to rest and answer some questions. You have T minutes of free time. You enter the site and see N new questions. To write an answer for each you'll need ti minutes. Of course, as a dedicated reputation gatherer, you want to answer as many questions as you can.
Can you write a program to calculate which questions do you have to answer to write maximum posts in T minutes?
Input
First line of input consists T
minutes you have for answering, and N
, how many new questions are on the site.
The second line has N numbers: time you need to answer qi question.
Output
Write either an array or numbers split with space: indexes of questions(counting from 0 or 1 - what is better for you) you should answer in order to write as many answers as you can. If you can't answer any questions, write nothing or anything to express that it's impossible. If there are several variants, write any.
Examples
Inputs Possible outputs
60 5
30 5 10 20 3
0 1 2 4
, 0 1 3 4
or 1 2 3 4
10 5
1 9 5 7 2
0 2 4
or 0 3 4
5 5
1 1 1 1 1
0 1 2 3 4
60 5
48 15 20 40 3
1 2 4
or 1 3 4
5 1
10
1 0
And of course it's code-golf, so the shortest code in bytes wins.