PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000050. Ghép đôi theo độ tuổi (A Match Making Problem)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Ghép đôi theo độ tuổi (A Match Making Problem)
A Match Making Problem
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
There are bachelors and spinsters. Starting with the oldest bachelor, match each to the closest-aged available spinster until one side is exhausted. Print the number of unmatched bachelors and, if positive, the youngest unmatched bachelor age.
Input
Line 1: . The next lines give bachelor ages; the following lines give spinster ages.
Output
Print Case 1: X when no bachelors remain, or Case 1: X Y otherwise, where is the remaining count and the youngest age.
Subtasks
- Subtask 1 (20 points): ; every age is in .
- Subtask 2 (30 points): ; every age is in .
- Subtask 3 (50 points): ; every age is in .
Examples
Input
4 2
5
5
10
15
20
18
Output
Case 1: 2 5
Explanation
There are four bachelors and two spinsters, leaving exactly two bachelors. The two oldest bachelors (15,10) are matched first; the remaining ages are 5 and 5, so the answer is Case 1: 2 5.