PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000059. Lựa chọn gần nhất chưa chắc tối ưu (Local Nearest Choice Counterexample)
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ựa chọn gần nhất chưa chắc tối ưu (Local Nearest Choice Counterexample)
Local Nearest Choice Counterexample
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Two groups of positions (processed in input order) and must be matched one-to-one, minimizing the sum of absolute distances. Compare a local nearest strategy that processes in input order and chooses the nearest unused (breaking ties by smaller position, then smaller original index), versus the global optimum. Print both costs.
Input
Line 1: . Line 2: positions . Line 3: positions .
Output
Print two integers: local-nearest cost and globally optimal cost.
Subtasks
- Subtask 1 (20 points): ; for every .
- Subtask 2 (30 points): ; for every .
- Subtask 3 (50 points): ; for every .
Examples
Input
2
10 0
9 20
Output
21 19
Explanation
For , the local choice is 9 (cost 1), leaving 20 for (cost 20), total 21. Matching 0 with 9 and 10 with 20 costs just .