#662
Silver II
Balancing Bacteria
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Farmer John has NN (1N21051\le N\le 2\cdot 10^5) patches of grass in a line, where patch ii has a level of bacteria that differs by aia_i from that of healthy grass (1015ai1015-10^{15}\le a_i \le 10^{15}). For example, if ai=3a_i = -3, then patch ii has a level of bacteria 3 lower than normal, and would need exactly 3 additional units of bacteria added to raise it to the point where it is considered healthy.

Farmer John wants to ensure every patch of grass is corrected to have a healthy level of bacteria. Conveniently, he owns two brands of pesticide that he can spray on his field, one that adds bacteria and one that removes bacteria. When Farmer John sprays either type of pesticide, he stands in patch NN (the rightmost patch) and selects a power level LL for his sprayer (1LN1 \leq L \leq N).

The sprayer has the most impact on patches near Farmer John, with diminishing effect farther away. If Farmer John chooses the pesticide that adds bacteria, then LL units of bacteria will be added to patch NN, L1L-1 units to patch N1N-1, L2L-2 units to patch N2N-2, and so on. Patches 1NL1 \ldots N-L will receive no bacteria, since the sprayer isn't set to a level powerful enough to reach them. Similarly, if Farmer John chooses the pesticide that removes bacteria, then LL units of bacteria will be removed from patch NN, L1L-1 units will be removed from patch N1N-1, and so on. Again, patches 1NL1 \ldots N-L will be unaffected.

Find the minimum number of times Farmer John has to apply his sprayer such that every patch of grass has the recommended value of bacteria for healthy grass. It is guaranteed that the answer is at most 10910^9.

Note that the large size of integers involved in this problem may require the use of 64-bit integer data types (e.g., a "long long" in C/C++).

입력

The first line contains NN.

The second line contains NN integers a1aNa_1\dots a_N, the initial bacteria levels of each patch of grass.

출력

The minimum number of applications necessary to make every patch of grass have the recommended value of bacteria for healthy grass.

예제 입력 1

2
-1 3

예제 출력 1

6

예제 입력 2

5
1 3 -2 -7 5

예제 출력 2

26

점수

Inputs 3-5: N103N \le 10^3, the answer is at most 10310^3 Inputs 6-10: N103N \le 10^3 Inputs 11-15: No additional constraints.

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Silver II1명 투표· 약 1개월 전
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.