CF-2277B•Codeforces

Sequence Decreasing

constructive algorithmsgreedy

Gracie Abrams - That's So True

An array bb 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):

  1. choose a non-empty subarray∗^{\text{∗}} of bb in which all elements are positive;
  2. decrease each element of this subarray by 11;
  3. choose one element of this subarray and remove it from bb, without changing the order of the remaining elements.

You are given an array aa of nn non-negative integers. Find the maximum length of a good subsequence†^{\text{†}} of aa, or report that aa has no good subsequence.

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

†^{\text{†}}A sequence cc is a subsequence of a sequence aa if cc can be obtained from aa 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 tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains a single integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5) — the length of the array aa.

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai≤1090 \le a_i \le 10^9) — the elements of the array aa.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

Output

For each test case, output a single integer — the maximum length of a good subsequence of aa, or 00 if no such subsequence exists.

Note

In the first test case, the array aa itself is good, since it is non-empty and consists only of zeros. Thus, the answer is 11.

In the second test case, it can be shown that aa has no good subsequence. Thus, the answer is 00.

Sample 1
Input
4
1
0
1
1
3
5 3 4
5
2 1 1 0 3
Output
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 In

No comments yet. Be the first to comment!

Actions

Open on Codeforces

About Platform

CO
Codeforces
External Judge

Problem Discussions

0

Have questions or want to share your solution approach? Join the discussion.

View / write comments