PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000192. Cộng theo lũy thừa hai (Powered Addition)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Cộng theo lũy thừa hai (Powered Addition)
Powered Addition
Source: Codeforces
Version: Phuoc Hung OJ (single-case adaptation where applicable)
Problem Statement
Given integers , at second you may choose any set of indices and add exactly to each selected value; choosing no indices is allowed. Find the minimum number of seconds required to make the array nondecreasing.
Input
The first line contains . The second contains integers (possibly negative).
Output
Print the minimum number of seconds.
Subtasks
- Subtask 1 (20 points): ; for every .
- Subtask 2 (30 points): ; for every .
- Subtask 3 (50 points): ; for every .
Examples
Example 1
Input
4
1 7 6 5
Output
2
Explanation
After the prefix maximum 7, the last two positions need increases of at least 1 and 2. Two seconds allow any increase from 0 to 3.
Example 2
Input
2
0 -4
Output
3
Explanation
The second element needs an increase of 4. Two seconds provide at most 1+2=3, but three seconds permit an increase of 4.