#BS0000156. Hai bệ đỡ (Two Platforms)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Hai bệ đỡ (Two Platforms)
Two Platforms
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
There are distinct points with integer coordinates. You can place two horizontal platforms, each of exactly length with integer endpoints. The platforms may have different heights and may overlap.
All points then fall vertically downward. A point is saved if it touches at least one platform, including its endpoints. Maximize the number of saved points by choosing the two placements.
Input
- The first line contains .
- The second line contains horizontal coordinates .
- The third line contains vertical coordinates . All point pairs are distinct.
Output
Print one integer: the maximum number of points saved by the two platforms.
Subtasks
- Subtask 1 (20 points): ; ; ; all are distinct.
- Subtask 2 (30 points): ; ; ; all are distinct.
- Subtask 3 (50 points): ; ; ; all are distinct.
Examples
Example 1
Input
7 1
1 5 2 3 1 5 4
1 3 6 7 2 5 4
Output
6
Explanation
The seven horizontal coordinates are . A platform spanning saves the three points with horizontal coordinates . A second spanning saves three points with coordinates . Only the point at is lost, for a total of . Two length- intervals cannot cover all five distinct integer x-coordinates , so is impossible.