#BS0000155. Các máy dịch chuyển – bản khó (Teleporters — Hard Version)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Các máy dịch chuyển – bản khó (Teleporters — Hard Version)
Teleporters (Hard Version)
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
On a number line there are positions . A teleporter at each position with costs coins to use. Walking one unit to either neighbor costs one coin. Every teleporter can be used at most once, and using one lets you teleport immediately to either endpoint or .
Initially you are at position with coins. You may walk and activate teleporters in any order, never exceeding the budget. Maximize the number of distinct teleporters used.
Input
- The first line contains .
- The second line contains positive integers .
Output
Print the maximum number of teleporters that can be used within budget .
Subtasks
- Subtask 1 (20 points): ; ; for all .
- Subtask 2 (30 points): ; ; for all .
- Subtask 3 (50 points): ; ; for all .
Examples
Example 1
Input
5 6
1 1 1 1 1
Output
2
Explanation
From , walk to position for one coin and activate teleporter for one more. Teleport to , walk back to for one coin, and activate teleporter for one coin. Thus two teleporters cost . Any third unused teleporter costs at least more coins, but only remain, so the maximum is 2.