PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#QHD0000090. Lịch nghỉ của ban nhạc (Muzicari)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Lịch nghỉ của ban nhạc (Muzicari)

Muzicari

Source: Kattis

Version: Phuoc Hung OJ Extended

Problem Statement

A band has NN members and performs during a concert lasting exactly TT minutes, from time 00 to time TT. Member ii needs one uninterrupted rest of exactly aia_i minutes. If the break begins at sis_i, it occupies the half-open interval [si,si+ai)[s_i,s_i+a_i) and must satisfy 0≤si≤T−ai0\le s_i\le T-a_i.

At every instant, at most two musicians may be resting. If three or more members rest simultaneously, the performance cannot continue. Intervals touching only at an endpoint do not overlap; for example, [0,3)[0,3) and [3,6)[3,6) are disjoint.

Output any valid schedule. The input guarantees that at least one valid solution exists, and several distinct schedules may be valid. Output starting times need not match those in the sample or the reference answer.

One convenient construction places musicians on two independent timelines, each of length TT. Breaks on the same timeline are consecutive and nonoverlapping. This reduces the construction to partitioning the break lengths into two subsets, each with total duration at most TT.

Input

The first line contains integers T,NT,N. The second line contains NN integers a1,a2,…,aNa_1,a_2,\ldots,a_N in member order. A valid schedule is guaranteed to exist.

Output

Print exactly NN integers s1,s2,…,sNs_1,s_2,\ldots,s_N in original input order, denoting each break's start time. Any valid schedule is accepted by a special checker; output is not compared byte-for-byte with a reference schedule.

Subtasks

  • Subtask 1 (20 points): 1≤T≤401\le T\le40, 1≤N≤121\le N\le12, 1≤ai≤T1\le a_i\le T; a valid schedule exists.

  • Subtask 2 (30 points): 1≤T≤5001\le T\le500, 1≤N≤1001\le N\le100, 1≤ai≤T1\le a_i\le T; a valid schedule exists.

  • Subtask 3 (50 points): 1≤T≤50001\le T\le5000, 1≤N≤5001\le N\le500, 1≤ai≤T1\le a_i\le T; a valid schedule exists.

Examples

Example 1

Input

8 3
4 4 4

Output

0 4 0

Explanation: Members 1 and 3 rest in [0,4)[0,4) while member 2 rests in [4,8)[4,8). At most two musicians rest simultaneously. Other outputs such as 0 2 4 are also valid.

Example 2

Input

10 5
7 5 1 2 3

Output

0 0 7 8 5

Explanation: The rest intervals are [0,7),[0,5),[7,8),[8,10),[5,8)[0,7),[0,5),[7,8),[8,10),[5,8). At no instant do more than two intervals overlap.