DOSA - Lalith Dosa

no tags 

Lalith is going to have dinner and he has N dosas in front of him with their prices represented by sequence of integers a1, a2, a3 ... an.

And he has decided to eat in a different manner. You are free to replace the price of any dosa with any positive integer.

How many prices (integers) must be replaced to make the resulting sequence strictly increasing?

Input

The first line of the test case contains an integer N - the number of dosas.

The next line contains N space separated integers where the ith integer is ai, representing the price of the i-th dosa.

Output

Output the minimal number of prices(integers) that should be replaced to make the sequence strictly increasing.

Constraints

0 < N <= 10^6

0 < ai <= 10^9

Sample Input #1

6

1 7 10 2 20 22

Sample Output #1

1

Sample Input #2

5

1 2 2 3 4 

Sample Output #2

3

Explanation 

In the first sample input, we can replace 2 with any integer between 11 and 19 to make the price sequence strictly increasing, hence the output is 1. 

In the second sample input, we can obtain 1, 2, 3, 4, 5 by changing the last three elements of the price sequence.

 


hide comments
vank: 2014-02-08 01:38:34

getting WA...
@arun lakshman can u provide test cases where it fails...
submission id:10840613

Last edit: 2014-01-11 08:26:55
Mitch Schwartz: 2014-02-06 14:37:52

@Ashwini: "You are free to replace the price of any dosa with any positive integer." So changing to zero is not allowed. (I know that in e.g. French the word that closely resembles "positive" includes zero, but that is not the case in English.)

Last edit: 2014-01-10 15:20:16
Ashwini: 2014-02-06 14:38:14

by changing are we suppose to confine our operations to only increasing that particular number???
if not so then output of second case is wrong .it should be 2 by decreasing first two numbers we get an strictly increasing sequence of 0 1 2 3 4

anurag garg: 2014-02-08 01:38:22

@author
I am getting wrong answer
can you provide the test case where it fails
submission id: 10833677

@ anurag garg : if u have N dosas ... then u must have N different prices in the result

Last edit: 2014-01-10 15:24:47

Added by:Arun Lakshman
Date:2014-01-09
Time limit:0.5s-1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Own