#BS0000406. Trung bình và trung vị (Average and Median)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Trung bình và trung vị (Average and Median)
Average and Median
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Takahashi has cards in a row, with integer on card . He chooses cards so that every adjacent pair contains at least one chosen card. Determine separately the greatest arithmetic mean and the greatest median of the chosen values. The two optima need not use the same selection. For chosen cards, the median is the value at position after sorting in nondecreasing order.
Input
Line 1 contains integer . Line 2 contains integers .
Output
Print two lines: the greatest mean, with absolute or relative error at most , then the greatest median as an exact integer.
Subtasks
- Subtask 1 (20 points): ; for every .
- Subtask 2 (30 points): ; for every .
- Subtask 3 (50 points): ; for every .
Examples
Input
6
2 1 2 1 1 10
Output
4
2
Explanation
Cards 2, 4 and 6 give mean 4. With cards, the sum is at most , giving a mean below 4. The four valid three-card choices are , , and ; only the last includes 10. Cards 1, 3, 5 and 6 yield sorted values with median 2. A greater median is impossible because only one card exceeds 2 and at least three must be chosen.