#FW0000106. Khách sạn và thang máy (Hotels)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Khách sạn và thang máy (Hotels)
Hotels
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
A hotel has floors numbered to ; guests enter at floor . Elevator stops at floors satisfying . Adjacent floors can be traversed by stairs at cost one; travel between any stops of a given elevator costs zero. For each destination floor compute the fewest stairs from ground. Output the worst value and the lowest floor attaining it.
Input
First line . Each of the next lines gives elevator parameters , with stops on floors congruent to modulo .
Output
Print two integers : the greatest minimum stair count, and the lowest floor attaining it.
Subtasks
-
Subtask 1 (40 points): . All input-format and graph conditions above apply.
-
Subtask 2 (60 points): . All input-format and graph conditions above apply.
Examples
Input
5 1
0 2
Output
1 1
Explanation
The elevator stops on floors 0, 2, 4. These floors require no stairs; floors 1 and 3 each require one. The maximum is 1 and the lowest achieving floor is 1.