luogu#P3515. [POI2011] Lightning Conductor

    ID: 7544 远端评测题 1000ms 125MiB 尝试: 6 已通过: 5 难度: 6 上传者: 标签>动态规划dp2011POI凸完全单调性凸单调

[POI2011] Lightning Conductor

题目描述

Progressive climate change has forced the Byteburg authorities to build a huge lightning conductor that would protect all the buildings within the city.

These buildings form a row along a single street, and are numbered from to .

The heights of the buildings and the lightning conductor are non-negative integers.

Byteburg's limited funds allow construction of only a single lightning conductor.

Moreover, as you would expect, the higher it will be, the more expensive.

The lightning conductor of height located on the roof of the building (of height ) protects the building (of height ) if the following inequality holds:

where denotes the absolute value of the difference between and .

Byteasar, the mayor of Byteburg, asks your help.

Write a program that, for every building , determines the minimum height of a lightning conductor that would protect all the buildings if it were put on top of the building .

输入格式

In the first line of the standard input there is a single integer () that denotes the number of buildings in Byteburg.

Each of the following lines holds a single integer () that denotes the height of the -th building.

输出格式

Your program should print out exactly lines to the standard output.

The -th line should give a non-negative integer denoting the minimum height of the lightning conductor on the -th building.

题目大意

给定一个长度为 nn 的序列 {an}\{a_n\},对于每个 i[1,n]i\in [1,n] ,求出一个最小的非负整数 pp ,使得 j[1,n]\forall j\in[1,n],都有 ajai+pija_j\le a_i+p-\sqrt{|i-j|}

1n5×1051 \le n \le 5\times 10^{5}0ai1090 \le a_i \le 10^{9}

6
5
3
2
4
2
4
2
3
5
3
5
4