#PU1373. USACO 2024 January Contest, Bronze — Problem 3. Balancing Bacteria
USACO 2024 January Contest, Bronze — Problem 3. Balancing Bacteria
USACO 2024 January Contest, Bronze — Problem 3. Balancing Bacteria
题目描述
Farmer John has () patches of grass in a line, where patch has a level of bacteria that differs by from that of healthy grass (). For example, if , then patch 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 (the rightmost patch) and selects a power level for his sprayer (). 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 units of bacteria will be added to patch , units to patch , units to patch , and so on. Patches 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 units of bacteria will be removed from patch , units will be removed from patch , and so on. Again, patches 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 .
输入格式
The first line contains . The second line contains integers , 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.
数据范围
Inputs 3-5: , the answer is at most Inputs 6-10: Inputs 11-15: No additional constraints. Problem credits: Rohin Garg
样例
样例 1
2
-1 3
6
Use the type of pesticide that removes bacteria, at a power level of 1, five
times. Then use the type of pesticide that adds bacteria, with a power level of
$2$, one time.
样例 2
5
1 3 -2 -7 5
26
提示
use of 64-bit integer data types (e.g., a "long long" in C/C++).