A. Sorting railway Cars time limit/test 2 seconds memory limit per test 256 megabytes input standard input output Stan Dard output
An infinitely long railway has a train consisting of n cars, numbered from 1 to n (the numbers of all cars are distinc T) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the order of increasing numbers. In ' one move ' can make one of the ' cars disappear from ' place and teleport it either to the beginning of the train, or To the "End of" train, at his desire. What is the minimum number of actions David Blaine needs to perform in order to sort the train? Input
The ' The ' input contains integer n (1≤n≤100)-the number of cars in the train.
The second line contains n integers pi (1≤pi≤n, PI≠PJ if i≠j)-the sequence of the numbers of the cars in the TRA In. Output
Print a single integer-the minimum number of actions needed to sort the railway cars. Examples input
5
4 1 2 5 3
Output
2
Input
4
4 1 3 2
Output
2
Note
In the ' the ' of the ' the ' and ' then ' the 5-th car to the ' end of the teleport ' 4-th car. Ac-code:
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include < algorithm>
#include <cstring>
using namespace std;
int main () {
int n,i,j,flag,a,dp[100005];
cin>>n;
flag=1;
Memset (Dp,0,sizeof (DP));
for (i=0;i<n;i++) {
cin>>a;
dp[a]=dp[a-1]+1;
}
Sort (dp+1,dp+n+1);
cout<<n-dp[n]<<endl;
return 0;