PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BS0000294. Xây bể cá (Building an Aquarium)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Xây bể cá (Building an Aquarium)
Building an Aquarium
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
There are coral columns of heights . Choose an integer tank height . Column i requires units of water if it is shorter than h, and zero otherwise. At most units of water are available. Find the maximum height.
Input
First line: . Second line: integers .
Output
Print one integer: the maximum achievable value.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; ; .
- Subtask 3 (50 points): ; .
Examples
Input 1
7 9
3 1 2 4 6 2 5
Output 1
4
Explanation
Height 4 costs 8 water units, while height 5 costs 13.
Input 2
1 1000000000
1
Output 2
1000000001
Explanation
All water is used on the single column.