Tickets
InterviewTime limit1sMemory limit128 MB
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 equal-size teletext pages carrying railway-ticket information over channels. Each page has a popularity — the probability that a viewer wants to read it. Let denote the popularity of page . The popularities are given in non-increasing order and sum to .
Pages receive an Internal Code (IC) from to assigned by decreasing popularity, so page is the most popular and page the least. Every channel serves a contiguous range of ICs:
- channel serves pages ,
- channel serves pages ,
- channel serves pages ,
with , 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 broadcasts . The delay of page is its -based position in its channel's broadcast order — the most popular page of a channel has delay , the next , and so on.
Minimize the average delay Since the popularities sum to , this equals the popularity-weighted average viewing delay.
Given , , and every page's popularity, choose that minimize the average delay and report the largest IC served by each channel.
Input
The first line contains an integer , the number of channels ().
The second line contains an integer , the number of pages (, with ).
Each of the next lines contains one real number in : the popularity of a page. The values are listed in non-increasing order.
Output
Print lines. Line contains the integer , the largest IC (page number) served by channel , for the channel assignment that minimizes the average delay.
If several assignments achieve the minimum, output the one whose sequence is lexicographically smallest.