CF2162A.Beautiful Average

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given an array aa of length nn.

Your task is to find the maximum possible average value of any subarray∗^{\text{∗}} of the array aa.

Formally, for any indices l,rl, r such that 1≤l≤r≤n1 \le l \le r \le n, define the average of the subarray al,al+1,…,ara_l, a_{l+1}, \dots, a_r as the sum of elements divided by the number of elements or: $$\texttt{avg}(l,r) = \frac{1}{r-l+1} \sum_{i=l}^{r} a_i$$ Output the maximum value of avg(l,r)\texttt{avg}(l,r) over all choices of l,rl, r.

∗^{\text{∗}}An array bb is a subarray of an array aa if bb can be obtained from aa by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.

给你一个长度为 nn 的数组 aa。

你的任务是找出数组 aa 中任意子数组∗^{\text{∗}} 的最大可能平均值。

形式化地,对于任意下标 l,rl, r 满足 1≤l≤r≤n1 \le l \le r \le n,定义子数组 al,al+1,…,ara_l, a_{l+1}, \dots, a_r 的平均值为元素之和除以元素个数,即:

avg(l,r)=1r−l+1∑i=lrai\texttt{avg}(l,r) = \frac{1}{r-l+1} \sum_{i=l}^{r} a_i

请输出所有 l,rl, r 取值中 avg(l,r)\texttt{avg}(l,r) 的最大值。

∗^{\text{∗}} 若数组 bb 可通过从数组 aa 的开头删除若干(可能为零或全部)元素、并从结尾删除若干(可能为零或全部)元素而得到,则称 bb 是 aa 的一个子数组。特别地,一个数组是其自身的子数组。

输入格式

The first line contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases.

The first line of each testcase contains a single integer nn (1≤n≤101 \le n \le 10) — the length of the array aa.

The second line of each testcase contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤101 \le a_i \le 10) — the elements of the array.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)——测试用例的数量。

每个测试用例的第一行包含一个整数 nn(1≤n≤101 \le n \le 10)——数组 aa 的长度。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤101 \le a_i \le 10)——数组的元素。

输出格式

For each testcase, output a single integer — the maximum average of any subarray of the given array.

It can be shown that the answer is always an integer.

对于每个测试用例,输出一个整数——给定数组中任意子数组的最大平均值。

可以证明答案始终为整数。

输入输出样例

  • 输入#1

    3
    4
    3 3 3 3
    5
    7 1 6 9 9
    5
    3 4 4 4 3

    输出#1

    3
    9
    4

输入解题思路,AI测评打分。不知道怎么写?

首页