#P6563. [SBCOI2020] 一直在你身旁

[SBCOI2020] 一直在你身旁

Background

In the blink of an eye, it is spring again...
Standing here, I finally realized
that my heart
has already become connected to that town protected by the Light Jade.
......
“It is spring again...”
“Looks like you are ready to stay here.”
“Actually, I do not have any big dreams. I am just trying hard to keep things as they are...”
“But as long as I can achieve my own dream, what does it matter...”
“But right now, I am truly very happy. Just like you said, I have found many joyful things...”
“I am also in the same world as you. There is nothing in this world that never changes.
So as long as you can find your happiness in other ways, that is enough...”
“Yeah, it is time to start a new life......”

“You are really obsessed with this town...”
“Because it is full of memories I do not want to forget...”

Problem Description

After returning to this town, her new job is to repair electric wires.
Now, one wire is broken. It is known that the wire length is one of 1,2,,n1,2,\cdots,n. Now, she needs to find out the wire’s length.

She can spend aia_i money to buy a wire of length ii. After buying this wire, she can know whether the required wire length is greater than ii.
It is guaranteed that a1a2an109a_1 \le a_2 \le \cdots \le a_n \le 10^9.
Ask what is the minimum amount of money she must spend to guarantee that she can determine the required wire length.

Input Format

This problem has multiple test cases.

The first line contains a positive integer TT, the number of test cases.

Then for each test case: one line contains an integer nn, and the next line contains nn integers a1,a2,,ana_1,a_2,\cdots,a_n.

Output Format

Output TT lines, each line containing one answer.

1
2
1 2
1

Hint

[Sample Explanation]

Buy a wire of length 11, and you can know whether the required length is greater than 11. Then you can determine whether it is 11 or 22, so the answer is 11.

Large sample link.

[Constraints]

This problem uses bundled testdata, with 44 subtasks in total.

(Subtask1)(10%)(Subtask 1)(10\%), n15n \le 15.

(Subtask2)(10%)(Subtask 2)(10\%), n500n \le 500.

(Subtask3)(30%)(Subtask 3)(30\%), n2000n \le 2000.

(Subtask4)(50%)(Subtask 4)(50\%), no additional constraints.

For 100%100\% of the testdata, 1n,n7100,T5001 \le n,\sum n \leq 7100,T \leq 500n\sum n denotes the sum of nn over all test cases.

Translated by ChatGPT 5