CF2162A.Beautiful Average
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array a of length n.
Your task is to find the maximum possible average value of any subarray∗ of the array a.
Formally, for any indices l,r such that 1≤l≤r≤n, define the average of the subarray al,al+1,…,ar 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) over all choices of l,r.
∗An array b is a subarray of an array a if b can be obtained from a 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.
给你一个长度为 n 的数组 a。
你的任务是找出数组 a 中任意子数组∗ 的最大可能平均值。
形式化地,对于任意下标 l,r 满足 1≤l≤r≤n,定义子数组 al,al+1,…,ar 的平均值为元素之和除以元素个数,即:
avg(l,r)=r−l+11i=l∑rai
请输出所有 l,r 取值中 avg(l,r) 的最大值。
∗ 若数组 b 可通过从数组 a 的开头删除若干(可能为零或全部)元素、并从结尾删除若干(可能为零或全部)元素而得到,则称 b 是 a 的一个子数组。特别地,一个数组是其自身的子数组。
输入格式
The first line contains a single integer t (1≤t≤104) — the number of test cases.
The first line of each testcase contains a single integer n (1≤n≤10) — the length of the array a.
The second line of each testcase contains n integers a1,a2,…,an (1≤ai≤10) — the elements of the array.
第一行包含一个整数 t(1≤t≤104)——测试用例的数量。
每个测试用例的第一行包含一个整数 n(1≤n≤10)——数组 a 的长度。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤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测评打分。不知道怎么写?