Candy Sales
InterviewTime limit6sMemory limit512 MB
For each day j, print the minimum over all i at most j of w_i + (j - i).
- Level
Medium5 of 10
- Topics
- Array, Prefix sum, Implementation
- Solved
- No attempts yet
Problem
Cathy's favourite candy brand is releasing n new flavours, one new flavour on each of the next n days. A pack of flavour , the flavour released on day , costs dollars on its release day. To get customers to try the new flavours, the price of a flavour goes up by one dollar on each day after its release. On day , a pack of the flavour released on day costs
dollars.
Cathy buys exactly one pack of candy on each of the next n days and wants to get the most candy for her money. Compute the price of the cheapest pack of candy available on each of the next n days. Every flavour has an unlimited number of packs and is on sale on its release day and on all later days.
Input
The input consists of two lines. The first line contains an integer (), the number of flavours. The second line contains integers (), where is the release-day price of flavour in dollars.
Output
Print n integers on one line, separated by single spaces. The i-th integer is the price of the cheapest pack of candy that Cathy can buy on day i.