PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BS0000334. Tưới cây đồng đều (Water the 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
Tưới cây đồng đều (Water the Trees)
Water the Trees
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given trees of initial heights , on each day starting at day 1 either skip the day or water one tree. Watering adds one unit on odd days and two units on even days. Minimize the number of days until all heights are equal.
Input
First line: . Second line: integers .
Output
Print the minimum number of days.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; ; all heights have the same parity.
- Subtask 3 (50 points): ; .
Examples
Input 1
3
1 2 4
Output 1
4
Explanation
Water tree 1 on day 1, tree 2 on day 2, skip day 3, and water tree 1 on day 4. Three days supply at most 4 units, less than the required 5.
Input 2
2
7 7
Output 2
0
Explanation
Both trees already have equal heights.