Sequence Decreasing
Gracie Abrams - That's So True
An array of non-negative integers is called good if it can be turned into a non-empty array consisting only of zeros by performing the following operation any number of times (possibly zero):
- choose a non-empty subarray of in which all elements are positive;
- decrease each element of this subarray by ;
- choose one element of this subarray and remove it from , without changing the order of the remaining elements.
You are given an array of non-negative integers. Find the maximum length of a good subsequence of , or report that has no good subsequence.
An array is a subarray of an array if can be obtained from by the deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.
A sequence is a subsequence of a sequence if can be obtained from by the deletion of several (possibly, zero or all) elements from arbitrary positions.
Input
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains a single integer () — the length of the array .
The second line of each test case contains integers () — the elements of the array .
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, output a single integer — the maximum length of a good subsequence of , or if no such subsequence exists.
Note
In the first test case, the array itself is good, since it is non-empty and consists only of zeros. Thus, the answer is .
In the second test case, it can be shown that has no good subsequence. Thus, the answer is .
4 1 0 1 1 3 5 3 4 5 2 1 1 0 3
1 0 0 5
Discussions & Comments
Share your approach or ask questions about this problem (0)
You must be logged in to comment or start a discussion on this problem.
Log InNo comments yet. Be the first to comment!
Actions
Open on CodeforcesAbout Platform
Problem Discussions
0Have questions or want to share your solution approach? Join the discussion.
View / write comments