#CT0000132. Dãy xấp xỉ tăng (Increasing Sequence Approximation)
Bài tập này chưa được xếp vào lộ trình.
Mục lục đề ⌄
Dãy xấp xỉ tăng (Increasing Sequence Approximation)
Increasing Sequence Approximation
Source: Bộ Giáo dục và Đào tạo
Version: Phuoc Hung OJ Extended
Problem Statement
Given an integer sequence , construct an integer sequence that is strictly increasing, meaning , and minimizes the sum of absolute deviations
The values may be negative even though the input values are nonnegative.
If several sequences achieve the same minimum sum, any one of them may be output. Print both the minimum sum and the corresponding sequence .
Input
- The first line contains a positive integer .
- The second line contains integers .
Output
- The first line prints the minimum value .
- The second line prints exactly strictly increasing integers achieving that minimum. Any optimal sequence is accepted.
Subtasks
- Subtask 1 (20 points): ; for all .
- Subtask 2 (20 points): ; for all .
- Subtask 3 (20 points): ; for all .
- Subtask 4 (20 points): ; for all .
- Subtask 5 (20 points): ; for all .
For each test, 50% of its score is awarded for the correct minimum deviation, and the remaining 50% is awarded for a valid optimal sequence .
Examples
Example 1
Input
7
1 5 1 7 3 1 3
Output
17
-1 0 1 2 3 4 5
Explanation: The output sequence is strictly increasing. Its total deviation is $|1-(-1)|+|5-0|+|1-1|+|7-2|+|3-3|+|1-4|+|3-5|=2+5+0+5+0+3+2=17$, the minimum possible value.
Liên quan
Trong các cuộc thi sau: