PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BF0000043. Người nhảy qua mái nhà (House Man)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Người nhảy qua mái nhà (House Man)
House Man
Source: HDU
Version: Phuoc Hung OJ Extended
Problem Statement
The houses have distinct heights and a fixed left-to-right order. Relocate them to distinct integer coordinates, preserving order. Successive houses in increasing height order must be at most units apart. Maximize the distance between the shortest and tallest houses, or output -1 if impossible.
Input
First line ; then pairwise distinct heights in original order.
Output
Print the greatest possible integer separation, or -1.
Subtasks
- Subtask 1 (20 points): , ; , all distinct.
- Subtask 2 (30 points): , ; , all distinct.
- Subtask 3 (50 points): , ; , all distinct.
Examples
Input
4 4
20 30 10 40
Output
3
Explanation
House is the shortest (height ) and house is the tallest (height ). The jumping order is . Coordinates preserve the input order, satisfy each jump bound , and place the extreme-height houses units apart, which is optimal.