PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000021. Trồng cây (Planting Trees)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Trồng cây (Planting Trees)
Planting Trees
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
There are seedlings. Exactly one seedling can be planted per day; seedling needs days after planting to finish growing. The party is held on the first day after all trees have finished growing. Find the earliest possible party day.
Input
The first line contains . The second line contains . The first planting day is day .
Output
Print the earliest possible party day.
Constraints
- .
- for .
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): Full constraints.
Examples
Input
4
2 3 4 3
Output
7
Explanation
The sample follows the ordering rule described in the Vietnamese explanation and produces the shown optimum.