#QHD0000090. Lịch nghỉ của ban nhạc (Muzicari)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Lịch nghỉ của ban nhạc (Muzicari)
Muzicari
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
A band has members and performs during a concert lasting exactly minutes, from time to time . Member needs one uninterrupted rest of exactly minutes. If the break begins at , it occupies the half-open interval and must satisfy .
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, and 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 . 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 .
Input
The first line contains integers . The second line contains integers in member order. A valid schedule is guaranteed to exist.
Output
Print exactly integers 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): , , ; a valid schedule exists.
-
Subtask 2 (30 points): , , ; a valid schedule exists.
-
Subtask 3 (50 points): , , ; a valid schedule exists.
Examples
Example 1
Input
8 3
4 4 4
Output
0 4 0
Explanation: Members 1 and 3 rest in while member 2 rests in . 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 . At no instant do more than two intervals overlap.