PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000282. Tổng chênh lệch tuyệt đối trong dãy đã sắp xếp (Sum of Absolute Differences in a Sorted Array)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Tổng chênh lệch tuyệt đối trong dãy đã sắp xếp (Sum of Absolute Differences in a Sorted Array)
Sum of Absolute Differences in a Sorted Array
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
Given an integer array in nondecreasing order, compute for every index . Equal elements still represent distinct positions. Output in the original order.
Input
First line: . Second line: integers in nondecreasing order.
Output
Print integers on one line, separated by spaces.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; ; .
- Subtask 3 (50 points): ; .
Example 1
Input
3
2 3 5
Output
4 3 5
Explanation
At 2: 0+1+3=4; at 3: 1+0+2=3; at 5: 3+2+0=5.
Example 2
Input
5
1 4 6 8 10
Output
24 15 13 15 21
Explanation
At 1: 0+3+5+7+9=24; at 6: 5+2+0+2+4=13; other positions are analogous.