F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Moonfang's Birthday

Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1158    Accepted Submission(s): 492


Problem Description
It's Moonfang's birthday,and his friends decided to buy him a copy of XianJianQiXiaZhuan V.
  
Since some of friends have more money available than others, nobody has to pay more than he can afford. Every contribution will be a multiple of 1 cent,i.e.,nobody can pay fractions of a cent.
  
Everybody writes down the maxumum amount he is able to contribute. Taking into account these maximum amounts from everybody, your task is to share the cost of the present as fairly as possible. That means, you minimize the largest distance of the contributions to 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 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.
 

Input
On the first line a positive integer: the number of test cases, at most 200. After that per test case:
  • One line with two integers p and n: the price of the present in cents (1 ¡Ü p ¡Ü 1 000 000) and the number of people (2 ¡Ü n ¡Ü 10000) who contribute to the present (including you).

  • One line with n integers ai (1 ¡Ü ai ¡Ü 1 000 000), where ai is the maximum amount, in cents, that the i-th person on the list is able to contribute.

 

Output
Per test case:
  • One line with 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 "IMPOSSIBLE" instead.
 

Sample Input
3 20 4 10 10 4 4 7 3 1 1 4 34 5 9 8 9 9 4
 

Sample Output
6 6 4 4 IMPOSSIBLE 8 7 8 7 4
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 16:12:36, Gzip enabled