Codey and Apples
https://www.hackerrank.com/contests/codenection-2023-final-round-open-category/challenges/cn-c23
Last updated
https://www.hackerrank.com/contests/codenection-2023-final-round-open-category/challenges/cn-c23
Last updated
An apple a day keeps the doctor away. Codey is a good friend and would like to keep its friends away from the doctors and keep them healthy.
Codey has n
bags, where the -th bag contains apples, and it has decided to share its apples with its m
friends. In order to keep this fair, Codey will only share the apples with its friends if it can choose some bags (at least 1 and possibly all) and evenly divide all the apples in those bags among the m
friends. In other words, the total number of apples in the bags Codey has chosen must be divisible equally among the m
friends.
Your task is to find the bags that meet this condition. If there are multiple answers, you may print any of them. If it is not possible, output .
Note that this problem uses a custom checker, so make sure your program compiles correctly and prints the output according to the format before submitting.
The first line contains integers n
, m
, which represent the number of bags and the number of friends, respectively.
The second line of input contains n
integers , each representing the number of apples in the -th bag.
In the next line, output k
unique integers separated by space, which are the indices of the selected bags for the second line.
Output the number of bags chosen, in the first line if it meets the condition.
If there are multiple answers, you may print any of them. If it is not possible, output .
Codey can choose the first 4
bags and get apples. Codey can then split one apple to each friend.