PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000084. Lắp đặt ra-đa (Radar Installation)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Lắp đặt ra-đa (Radar Installation)
Radar Installation
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
The coastline is the -axis. Islands lie at points with . Radar stations may be placed anywhere on the coastline and each covers islands within Euclidean distance . Find the minimum number of stations needed to cover all islands, or -1 if any island is unreachable.
Input
The first line contains . Each of the next lines contains .
Output
Print the minimum number of radars, or -1 if any island cannot be covered.
Subtasks
- Subtask 1 (20 points): ; ; ; .
- Subtask 2 (30 points): ; ; ; .
- Subtask 3 (50 points): ; ; ; .
Examples
Input
3 2
1 2
-3 1
2 1
Output
2
Explanation
The island can only be covered from coastal coordinate . From there, is also within radius . The leftmost island requires another radar, so two radars are necessary.