PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BS0000309. Nhật ký độ cao (Tourist's Notes)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Nhật ký độ cao (Tourist's Notes)
Tourist's Notes
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
A hike lasts n days with integer heights satisfying . The remaining m notes are in strictly increasing day order and prescribe . Find the greatest possible peak or report inconsistent notes.
Input
First line: n,m. Next m lines contain .
Output
Print the greatest possible height, or IMPOSSIBLE for inconsistent notes.
Subtasks
- Subtask 1 (20 points): ; ; ; ; .
- Subtask 2 (30 points): ; ; ; ; ; .
- Subtask 3 (50 points): ; ; ; ; .
Examples
Input 1
8 2
2 0
7 0
Output 1
2
Explanation
Five steps separate the two zero heights. A feasible sequence is (1,0,1,2,2,1,0,1), with peak 2.
Input 2
8 3
2 0
7 0
8 3
Output 2
IMPOSSIBLE
Explanation
Days 7 and 8 differ by 3, exceeding 1.