#P2035. [USACO08JAN] iCow B

[USACO08JAN] iCow B

Description

Exhausted by endless farm work, Farmer John plans to relax by listening to music on his newly purchased iCow in the MP3 player market. FJ’s iCow stores N(1N1,000)N(1 \le N \le 1{,}000) songs, numbered 1..N1..N in order. The playback order of the songs is determined by an algorithm designed by Farmer John:

  • The ii-th song has an initial weight Ri (1Ri10,000)R_i\ (1 \le R_i \le 10{,}000).
  • When a song finishes playing, the next song to play is the one with the maximum weight among all songs (if two or more songs have the same weight, the one with the smallest index among them is chosen).
  • After a song finishes playing, its weight is evenly distributed to the other N1N-1 songs, and its own weight becomes zero.
  • If a song’s weight cannot be evenly distributed (i.e., it is not divisible by N1N-1), then the remainder after division by N1N-1 will be distributed in units of 11 to the songs earlier in index order (that is, song 11, song 22, and so on; of course, skip the song that just played), until the extra part is fully distributed.

After the selected next song finishes playing, this algorithm is executed again to adjust the weights and select the following song.

Please compute which songs are played first for the initial T (1T1000)T\ (1 \le T \le 1000) plays according to FJ’s algorithm.

Input Format

The first line contains two integers separated by a space: NN and TT.

The second to the (N+1)(N+1)-th lines: line i+1i+1 contains one integer RiR_i.

Output Format

Output TT lines. On the ii-th line, output one integer, the index of the ii-th song played by iCow.

3 4
10
8
11

3
1
2
3

Hint

Before each play, the weights of the three songs are:

  • [10,8,11][10,8,11]. Play #3\#3, 11/2=511/2 = 5, remainder 11.
  • [16,13,0][16,13,0]. Play #1\#1, 16/2=816/2 = 8.
  • [0,21,8][0,21,8]. Play #2\#2, 21/2=1021/2 = 10, remainder 11.
  • [11,0,18][11,0,18]. Play #3\#3...

Translated by ChatGPT 5