#GL0000155. Bàn bốn chân từ các chồng tiền xu (Mint)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Bàn bốn chân từ các chồng tiền xu (Mint)
Mint
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
A table has four legs made of stacks of coins. Each leg consists of coins of a single type, and four distinct coin types must be used. All four legs must have exactly the same height. Coin thicknesses and desired heights are positive integers measured in hundredths of a millimetre. There is an unlimited supply of each coin type.
For each desired height , determine the greatest feasible common leg height not exceeding , and the least feasible height not smaller than . You may choose a different set of four coin types for each table. Output as the lower bound if no positive feasible height is at most .
Input
The first line contains . The next lines contain coin thicknesses ; the next lines contain target heights .
Output
For each target height, print two integers on one line: the greatest feasible height at most the target and the least feasible height at least the target.
Subtasks
- Subtask 1 (20 points): ; ; ; .
- Subtask 2 (30 points): ; ; ; .
- Subtask 3 (50 points): ; ; ; .
Examples
Input
4 2
50
100
200
400
1000
2000
Output
800 1200
2000 2000
Explanation
There are exactly four types, so each leg uses one of them. Their LCM is . The feasible positive heights are . Thus the closest feasible heights around are and ; itself is feasible.