#BS0000448. Ghép học sinh với gia sư lập trình (Programming Tutors)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Ghép học sinh với gia sư lập trình (Programming Tutors)
Programming Tutors
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
The Bruce Arden Programming Collective assigns experienced programming tutors to beginners. There are students and tutors, and each person must belong to exactly one student–tutor pair.
Travel takes place on a city grid, so the distance between locations and is
Different people may live at the same location.
To keep the assignment fair, minimize the greatest travel distance incurred by any pair rather than the sum of all distances. Find the smallest achievable maximum distance over all complete assignments.
Input
The first line contains integer , the number of students and also the number of tutors.
The next lines contain integers , the location of student .
The final lines contain integers , the location of tutor .
Output
Print one integer : the smallest bound on the distance of every pair in a complete assignment.
Subtasks
- Subtask 1 (20 points): ; for every ; coincident locations are allowed.
- Subtask 2 (30 points): ; for every ; coincident locations are allowed.
- Subtask 3 (50 points): ; for every ; coincident locations are allowed.
Examples
Input 1
2
0 0
0 3
0 2
0 5
Output 1
2
Explanation 1
Pair student 1 with tutor 1 and student 2 with tutor 2. Both distances equal 2. Student 1 is at least 2 away from either tutor, establishing optimality.
Input 2
4
0 1
0 2
0 3
0 4
1 0
1 1
1 2
1 3
Output 2
2
Explanation 2
Pair the -th student with the -th tutor. Each pair differs by 1 on both axes, giving distance 2. The last student is at least 2 from every tutor.
Input 3
3
0 5
5 2
4 5
3 3
5 2
5 2
Output 3
5
Explanation 3
Pair in input order, obtaining distances , , and . Student has minimum possible distance 5. The two tutors at are distinct people.
Input 4
2
0 0
0 5
-1 4
8 3
Output 4
10
Explanation 4
Pairing in input order gives distances 5 and 10. Swapping tutors makes the first student travel . These are the only two bijections, so the optimum is 10.
Adapted from BAPC 2016 Jury, CC BY-SA 4.0 (https://creativecommons.org/licenses/by-sa/4.0/); rewritten for PHOJ.