This page is still under construction.

Parts of this page are still being built. What you see may change.

Tickets

Interview

Time limit1sMemory limit128 MB

Summary
Split L pages of non-increasing popularity into D contiguous channel blocks to minimize the popularity-weighted sum of within-block delay positions, breaking ties by the lexicographically smallest block boundaries.
Level

Medium6 of 10

Topics
Dynamic programming, Greedy, Array, Prefix sum
Solved
No attempts yet

Problem

The Hellenic Broadcasting Company (HBC) broadcasts LL equal-size teletext pages carrying railway-ticket information over DD channels. Each page has a popularity — the probability that a viewer wants to read it. Let pip_i denote the popularity of page ii. The popularities are given in non-increasing order and sum to 11.

Pages receive an Internal Code (IC) from 11 to LL assigned by decreasing popularity, so page 11 is the most popular and page LL the least. Every channel serves a contiguous range of ICs:

  • channel 11 serves pages [1,M1][1, M_1],
  • channel 22 serves pages [M1+1,M2][M_1 + 1, M_2],
  •   …\;\dots
  • channel DD serves pages [MD−1+1,L][M_{D-1} + 1, L],

with 1≤M1<M2<⋯<MD=L1 \le M_1 < M_2 < \dots < M_D = L, so every channel serves at least one page.

Within a channel the pages are broadcast cyclically (round-robin) in order of decreasing popularity: a channel holding pages A,B,CA, B, C broadcasts A,B,C,A,B,C,…A, B, C, A, B, C, \dots. The delay did_i of page ii is its 11-based position in its channel's broadcast order — the most popular page of a channel has delay 11, the next 22, and so on.

Minimize the average delay ∑i=1Lpi di.\sum_{i=1}^{L} p_i \, d_i . Since the popularities sum to 11, this equals the popularity-weighted average viewing delay.

Given DD, LL, and every page's popularity, choose M1,…,MDM_1, \dots, M_D that minimize the average delay and report the largest IC served by each channel.

Input

The first line contains an integer DD, the number of channels (1≤D≤201 \le D \le 20).

The second line contains an integer LL, the number of pages (1≤L≤3001 \le L \le 300, with D≤LD \le L).

Each of the next LL lines contains one real number in [0,1][0, 1]: the popularity of a page. The values are listed in non-increasing order.

Output

Print DD lines. Line jj contains the integer MjM_j, the largest IC (page number) served by channel jj, for the channel assignment that minimizes the average delay.

If several assignments achieve the minimum, output the one whose sequence M1,M2,…,MDM_1, M_2, \dots, M_D is lexicographically smallest.

Examples3

  1. Example 1

    Input
    4
    8
    0.28390927493533
    0.17355945737314
    0.13014380192001
    0.10610039157939
    0.09055467526374
    0.07955952705969
    0.07131156575676
    0.06486130611193
    
    Expected output
    1
    3
    5
    8
    
  2. Example 2

    Input
    1
    1
    1.0
    
    Expected output
    1
    
  3. Example 3

    Input
    5
    5
    0.40
    0.25
    0.18
    0.12
    0.05
    
    Expected output
    1
    2
    3
    4
    5