eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач
Задачи

Fair Division

Fair Division

It's your friend's birthday, and you and some other people decided to buy him a copy of StarCraft II, because who wouldn’t want to have that? You agreed to divide the costs as fairly as possible. Since some of you have more money available than others, you also agreed that nobody has to pay more than he can afford. Every contribution will be a multiple of \textbf{1} cent, i.e., nobody can pay fractions of a cent. Everybody writes down the maximum amount he is able to contribute. Taking into account these maximum amounts from everybody, you share the cost of the present as fairly as possible. That means, you minimize the largest distance of the contributions to (\textbf{1/n})-th of the total cost. In case of a tie, minimize the second largest distance, and so on. Since the smallest unit of contribution is \textbf{1} cent, there might be more than one possible division of the cost. In that case, persons with a higher maximum amount pay more. If there is still ambiguity, those who come first in the list pay more. Since you bought the present, it is your task to figure out how much everybody has to pay (including you). \InputFile On the first line a positive integer: the number of test cases, at most \textbf{100}. After that per test case: \begin{itemize} \item One line with two integers \textbf{p} and \textbf{n}: the price of the present in cents (\textbf{1} ≤ \textbf{p} ≤ \textbf{1000000}) and the number of people (\textbf{2} ≤ \textbf{n} ≤ \textbf{100}) who contribute to the present (including you). \item One line with \textbf{n} integers \textbf{a_i} (\textbf{1} ≤ \textbf{a_i} ≤ \textbf{1000000}), where \textbf{a_i} is the maximum amount, in cents, that the \textbf{i}-th person on the list is able to contribute. \end{itemize} \OutputFile Per test case: \begin{itemize} \item One line with \textbf{n} integers: the amounts each person has to contribute according to the scheme. If the total cost cannot be divided according to the above rules, the line must contain "\textbf{IMPOSSIBLE}" instead. \end{itemize}
Лимит времени 1 секунда
Лимит использования памяти 64 MiB
Входные данные #1
3
20 4
10 10 4 4
7 3
1 1 4
34 5
9 8 9 9 4
Выходные данные #1
6 6 4 4
IMPOSSIBLE
8 7 8 7 4
Источник NWERC-2010