For each day j, print the minimum over all i at most j of w_i + (j - i).
Medium5ArrayPrefix sumImplementationInterviewNo attempts yetTime limit6sMemory limit512 MBCathy's favourite candy brand is releasing n new flavours, one new flavour on each of the next n days. A pack of flavour i, the flavour released on day i, costs wi 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 j≥i, a pack of the flavour released on day i costs
wi+(j−i)
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.
The input consists of two lines. The first line contains an integer n (1≤n≤200000), the number of flavours. The second line contains n integers w1,w2,…,wn (1≤wi≤100000), where wi is the release-day price of flavour i in dollars.
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.