Beautiful Sequence
Practice
4.3 (12 votes)
Binary search
Dynamic programming
Easy
Problem
8% Success 11189 Attempts 30 Points 4s Time Limit 256MB Memory 500 KB Max Code

A sequence of integers is called a beautiful sequence if all the integers in it are positive and it is a strictly increasing sequence.

Given a sequence of integers, you have to make it a beautiful sequence. For that you can change any element you want, but you should make as less changes as possible in order to make it a beautiful sequence.

Input

The first line of input is an integer T(T <= 5), the number of test cases. Each test case contains 2 lines.

The first line of the test case contains an integer (0 < N <= 100000), i.e. the number of elements in the original sequence.

The second line contains N positive integers, no larger than 2000000000, which forms the original sequence.

Output

For each test case output the minimal number of elements you must change in the original sequence to make it a beautiful sequence.

Explanation for sample Input/Output

For the 1st test case you needn't to change any elements.
For the 2nd test case you can change 3 into 1 and change 1 into 3.
For the 3rd test case you can change 10 into 1.
For the 4th test case you can change the last three 2s into 3,4 and 5.

UPDATE

Test cases have been made stronger and all previous submissions have been rejudged.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
10 votes
Tags:
ApprovedData StructuresDynamic ProgrammingEasyReadyRecruitapproved
Points:30
7 votes
Tags:
CombinatoricsDynamic ProgrammingAlgorithmsStringIntroduction to Dynamic Programming 1
Points:30
40 votes
Tags:
Basic ProgrammingEasyReady
Editorial

No editorial available for this problem.