Rent Division

시간 제한5초메모리 제한2048 MB

요약
각 룸메이트가 낸 기타 비용과 총 월세가 주어질 때, 모든 사람의 총 부담액이 같아지도록 각자의 월세 분담액을 구한다.
난이도

쉬움10점 중 3점

유형
수학, 그리디, 구현
정답자
아직 제출이 없습니다

문제

In an apartment just down the street from Colorado School of Mines, there are NN roommates who are trying to figure out how to pay their rent every month. These roommates also have other expenses that they share as well. Rather than using Venmo to share those expenses like sane individuals, they have decided to handle all money exchanges by paying different proportions of rent at the beginning of each month.

For example, let's say there are N=4N = 4 roommates in an apartment: Jack, Joseph, Jordan, and David. Jack always pays the Internet and utility bills, totalling \\81( (c_1),whileeveryoneelsepaysnothing(), while everyone else pays nothing (c_2 = c_3 = c_4 = \00). Assuming rent this month is \\1963( (R$), how much should each person pay (rounded up), so that each of their total contributions (including expenses that they have already paid) are equal and so that the entire rent is paid?

These roommates are entirely stumped because this is such a difficult calculation. Your mission, if you choose to accept it, is to aid these NN roommates in finding out what portion of the rent they need to pay individually. If it is not possible, then you should output "not possible", and everyone has to get Venmo. This happens if someone pays too much in other expenses and would need to be paid, rather than pay, rent.

입력

The first line consists of one integer, NN (1≤N≤100 0001 \leq N \leq 100\ 000) which is the number of roommates. The next NN lines each have one integer c_ic\_i (0≤c_i≤10 0000 \leq c\_i \leq 10\ 000) indicating how much person ii has paid on non-rent expenses.

The last line is the rent due this month, RR (0≤R≤500 000 0000 \leq R \leq 500\ 000\ 000).

출력

If it is not possible for the total contributions from each roommate to be equal, then output a single line with the words "not possible".

If it is possible for each of the NN roommates to make an equal total contribution, then output NN lines each with an integer, p_ip\_i, indicating how much of the rent the corresponding person, person ii, should pay.

예제3

  1. 예제 1

    입력
    4
    81
    0
    0
    0
    1963
    
    예상 출력
    430
    511
    511
    511
    
  2. 예제 2

    입력
    1
    0
    1
    
    예상 출력
    1
    
  3. 예제 3

    입력
    5
    1000
    0
    0
    0
    0
    100
    
    예상 출력
    not possible