PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#FT0000128. Lễ hội tiếng bò (MooFest)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Lễ hội tiếng bò (MooFest)
MooFest
Source: Luogu
Version: Phuoc Hung OJ Extended
Problem Statement
John's cows are attending MooFest. Cow stands at integer coordinate and has hearing value . All cow positions are distinct.
The volume of communication between cows and is . Every unordered pair of distinct cows communicates. Compute the sum of all these volumes, counting each pair exactly once. Use the maximum hearing value, not the minimum or the sum.
Input
- First line: .
- Next lines: two integers in that order.
Output
Print the total volume over all unordered pairs of cows.
Subtasks
- Subtask 1 (20 points): ; ; all positions are pairwise distinct.
- Subtask 2 (30 points): ; ; all positions are pairwise distinct.
- Subtask 3 (50 points): ; ; all positions are pairwise distinct.
Examples
Example 1
Input
4
3 1
2 5
2 6
4 3
Output
57
Explanation
The six pairwise volumes are (in lexicographic pair order). Their sum is .
Example 2
Input
3
1 2
3 5
2 8
Output
30
Explanation
For cows , the pairwise volumes are , , and , totaling 30.