Official algorithmic problem description and constraints.
You are given an array π
of length π
.
Your task is to find the maximum possible average value of any subarray
β
of the array π
.
Formally, for any indices π,π
such that 1β€πβ€πβ€π
, define the average of the subarray π
π
,π
π+1
,β¦,π
π
as the sum of elements divided by the number of elements or:
πππ(π,π)=1
πβπ+1
β
π=π
π
π
π
Output the maximum value of πππ(π,π)
over all choices of π,π
.
β
An array π
is a subarray of an array π
if π
can be obtained from π
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.
Input
The first line contains a single integer π‘
(1β€π‘β€10
4
) β the number of test cases.
The first line of each testcase contains a single integer π
(1β€πβ€10
) β the length of the array π
.
The second line of each testcase contains π
integers π
1
,π
2
,β¦,π
π
(1β€π
π
β€10
) β the elements of the array.
Output
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.
Example
Input
Copy
3 4 3 3 3 3 5 7 1 6 9 9 5 3 4 4 4 3
Output
Copy
3 9 4
Detailed video explanations, mathematical intuition, and clean C++ implementation code.