#P4857. Infinite Train Ticket Inspection

    ID: 18099 Type: Default 1000ms 256MiB

Infinite Train Ticket Inspection

Infinite Train Ticket Inspection

An infinite train has k ticket inspectors. Each inspector i inspects \(a_i\) carriages in one move. Initially, all inspectors are positioned at carriage \(0\). The train conductor issues a total of n commands. On each command, the inspector who is farthest to the left (i.e. the one with the smallest carriage number) is chosen. In case of ties, the inspector with the smallest index is chosen. The selected inspector then moves to the right by \(a_i\) carriages (i.e. his position is increased by \(a_i\)).

After applying n commands, output for each inspector the command number during which he made his final move.

Note: The carriage numbers and command counts start from \(0\) and \(1\) respectively.

inputFormat

The input consists of two lines:

  1. The first line contains two integers \(n\) and \(k\), representing the number of commands and the number of inspectors respectively.
  2. The second line contains \(k\) integers \(a_1, a_2, \dots, a_k\), where \(a_i\) is the number of carriages inspector \(i\) inspects during each move.

outputFormat

Output a single line containing \(k\) integers. The \(i\)-th integer is the command number on which the \(i\)-th inspector performed his last move.

sample

3 3
1 2 3
1 2 3