NZD - Okružno 2012
An array a of n positive integers is given to you. In one move you can choose any two adjacent elements and replace them with their sum. For example, if we choose elements ai and ai + 1, the array (a1, a2, ..., ai, ai + 1, ... an) will become (a1, a2, ..., ai + ai + 1, ... an). This action can then be repeated on newly formed arrays (Notice that the number of elements decreases by 1 after every move).
Your task is to apply a number of moves to this array, so that in the end you have exactly k numbers remaining with the greatest possible common divisor.
6 3
12 7 3 2 15 15Sample output:
6
12 12 30Explanation:
If we execute the following moves (12, 7, 3, 2, 15, 15) → (12, 10, 2, 15, 15) → (12, 10, 2, 30) → (12, 12, 30) we get numbers 12, 12 i 30 whose greatest common divisor is 6. It is impossible to get 3 numbers with a larger greatest common divisor.
Submit solution
Coming laterThe grading service will be connected in a later migration step. You can inspect the task and your previous results now.