## COCI '07 Contest 4 #4 Muzicari

View as PDF

Points: 15
Time limit: 0.6s
Memory limit: 32M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

"The Drinking Musicians", a widely known and popular folk group, are coming to your town. The musicians are known not only by their playing skills, but also their rough character. They never arrive on time, don't know which town they're in, and frequently have trouble finding the stage.

Additionally, during the concert, each of the musicians at one point takes a break. If three or more of them are on a break at the same time, they start stirring trouble in town and the rest of the group start panicking and playing the wrong chords.

The concert will be minutes long, during which each of the members will take a break. The length of the break is known for each member.

Help the organizer of the concert by writing a program that determines how to schedule the breaks of the member so that, at any given moment, at most two are absent from the stage. All breaks must be entirely during the concert.

#### Input Specification

The first line of input contains the integers and , the length of the concert in minutes and the number of musicians in the group.

The next line contains integers separated by single spaces, the length of the break in minutes for each member.

Note: The input data will be such that a solution, although not necessarily unique, will always exist.

#### Output Specification

For each musician output one integer, the number of minutes the musician will spend on stage before going on the break.

Output the musicians in the same order they were given in the input.

#### Sample Input 1

8 3
4 4 4

#### Sample Output 1

0 2 4

#### Sample Input 2

10 5
7 5 1 2 3

#### Sample Output 2

3 3 9 0 0

• commented on Sept. 3, 2017, 10:22 a.m. edited

Clarification

Would

0 0 4

be a valid answer for sample #1, and

3 2 7 0 0

valid for sample #2?