#P5774. [JSOI2016] 病毒感染

[JSOI2016] 病毒感染

Description

A severe Jebola virus outbreak has occurred in a remote border town of JOSI, and many people are infected and in critical condition. Computer scientist JYY has urgently developed a Jebola vaccine using the latest algorithm and rushes to the disaster area to treat patients.

There are NN towns with Jebola outbreaks. Because these towns are located on the border, they are connected only by one long straight road. For convenience, we number the towns from 11 to NN in the order along the road. JYY will arrive at town 11 early on the first day.

Initially, in town ii, there are aia_i patients infected with the Jebola virus.

Each day, JYY may choose one of the following:

  1. Spend one day to completely cure all Jebola patients in the town where JYY currently is. On this day, no patients will die.
  2. Spend one day to travel to an adjacent town.

At the start of a day, if there are kk Jebola patients in a town, then by the end of that day, these kk patients will infect another kk healthy villagers in that town and then die. Therefore, for town ii, as long as its outbreak has not been completely eliminated by JYY, every day there will be aia_i villagers who die.

JYY wants to take actions so that when the epidemic is completely eliminated overall, the total number of villagers who die is as small as possible.

To achieve this, JYY sometimes will arrive at a town but not treat the villagers. If such behavior is not restricted, it often leads to even more serious consequences.

Consider this situation: suppose when JYY first arrives at town ii, he does not treat anyone and goes directly to another town. Because the people in town ii are desperate to survive, once JYY moves in the direction closer to town ii, the villagers of town ii will think JYY is coming to save them, and they will have great hope. Later, if JYY turns around again and moves in the direction farther away from town ii, the villagers of town ii will fall into despair due to huge disappointment.

To avoid this, JYY sets the following rule for his trip:

Suppose JYY enters town ii and leaves immediately on the second day (and the outbreak in town ii is not cured). If on some later day, JYY travels from town jj to town kk and satisfies ki<ij|k-i| \lt |i-j|, then in the days after that JYY may only move toward town ii until he reaches town ii and immediately cures the patients there. While traveling toward town ii, JYY may choose to cure the outbreaks in towns he passes through.

For example, if JYY has the following schedule:

Day 1: travel from town 11 to town 22.

Day 2: travel from town 22 to town 33.

Day 3: cure town 33.

Day 4: travel to town 22.

At this time, for the next three days, JYY has only one possible choice:

Day 5: cure town 22.

Day 6: travel to town 11.

Day 7: cure town 11.

JYY wants to know, before all towns are cured, at least how many villagers will die from Jebola.

Input Format

The first line contains a positive integer NN.

The next line contains NN integers, which are a1,a2,...,aNa_1,a_2,...,a_N.

Output Format

Output one line with one integer, representing the number of villagers who will die under the optimal schedule.

6
40 200 1 300 2 10
1950

Hint

Sample Explanation

We use C(k)C(k) to denote curing town kk, and iji \rightarrow j to denote traveling from town ii to town jj. Using commas to separate the plan for each day, the optimal strategy in the sample is:

$1 \rightarrow 2 , C(2),2 \rightarrow 3 , 3 \rightarrow 4 , C(4) , 4 \rightarrow 3 , C(3) , 3 \rightarrow 2 , 2 \rightarrow 1 , C(1) , 1 \rightarrow 2 , 2 \rightarrow 3 , 3 \rightarrow 4 , 4 \rightarrow 5 , 5 \rightarrow 6 , C(6) , 6 \rightarrow 5 , C(5)$;

The whole process takes 1818 days.


Constraints

For 10%10\% of the testdata, N10N \le 10.

For 30%30\% of the testdata, N20N \le 20.

For 50%50\% of the testdata, N60N \le 60.

For 100%100\% of the testdata, 1N30001 \le N \le 3000, 1ai1091 \le a_i \le 10^9.

Translated by ChatGPT 5