#abc236e. E - Average and Median

E - Average and Median

Score : 500500 points

问题描述

我们有 NN 张卡片。第 ii 张卡片(1iN1 \leq i \leq N)上写有一个整数 AiA_i

Takahashi 将从这些卡片中选择任意数量的卡片。但是,对于每个 ii1iN11 \leq i \leq N - 1),至少需要选择第 ii 张和第 (i+1)(i+1) 张卡片中的其中一张。

找出以下两个值:

  • 所选卡片上整数的最大可能平均值
  • 所选卡片上整数的最大可能中位数

这里,nn 个整数的中位数定义为其中第 n2\lceil \frac{n}{2} \rceil 小的那个数,其中 x\lceil x \rceil 表示不小于 xx 的最小整数。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

We have NN cards. The ii-th card (1iN)(1 \leq i \leq N) has an integer AiA_i written on it.

Takahashi will choose any number of cards from these. However, for each ii (1iN1)(1 \leq i \leq N - 1), at least one of the ii-th and (i+1)(i+1)-th cards must be chosen.

Find the following values.

  • The maximum possible average of the integers written on the chosen cards
  • The maximum possible median of the integers written on the chosen cards

Here, the median of the nn integers is defined to be the n2\lceil \frac{n}{2} \rceil-th smallest of them, where x\lceil x \rceil is the smallest integer not less than xx.

Constraints

  • 2N1052 \leq N \leq 10^5
  • 1Ai1091 \leq A_i \leq 10^{9}
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

A1A_1 \ldots ANA_N

Output

Print two lines. The first and second lines should contain the maximum possible average and maximum possible median of the integers written on the chosen cards, respectively. For the average, your output will be considered correct when its relative or absolute error from the exact answer is at most 10310^{-3}.

Sample Input 1

6
2 1 2 1 1 10

Sample Output 1

4
2

Choosing the 22-nd, 44-th, and 66-th cards makes the average of the written integers 123=4\frac{12}{3} = 4, which is the maximum possible.

Choosing the 11-st, 33-rd, 55-th, and 66-th cards makes the median of the written integers 22, which is the maximum possible.

Sample Input 2

7
3 1 4 1 5 9 2

Sample Output 2

5.250000000
4

For the average, your output may contain some degree of error: for example, the output 5.24915.2491 is still considered correct. For the median, however, the exact value must be printed.

update @ 2024/3/10 10:14:03