C. Sorting Railway Cars
An infinitely long railway have a train consisting of n cars, numbered from 1 to n (The Numbe Rs of all the cars is distinct) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the order of increasing numbers. In one move he can make one of the cars disappear from its place and teleport it either to the beginning of the train, or To the end of the train in his desire. What's the minimum number of actions David Blaine needs to perform on order to sort the train?
Input
The first line of the input contains integer n (1≤ n ≤100)-the number of cars in the TRA In.
The second line contains n integers pi (1≤ pi ≤< C14>n, pi ≠ pJ if i ≠ J)- The sequence of the numbers of the cars in the train.
Output
Print a single integer-the minimum number of actions needed to sort the railway cars.
Sample Test (s)
input
5
4 1 2) 5 3
Output
2
input
4
4 1 3 2
Output
2
Note
In the first sample you need first to teleport the 4-th car, and then the 5-th car to the end of the train.
Test Instructions : give the sequence of n length, each can move the number of any position to the sequence head, the sequence tail calculates an operation, ask you at least after several operations to make it orderly;
The most continuous sub-sequence ,
//Meek///#include<bits/stdc++.h>#include <iostream>#include<cstdio>#include<cmath>#include<string>#include<cstring>#include<algorithm>#include<queue>#include<map>#include<Set>#include<stack>#include<sstream>#include<vector>using namespacestd; typedefLong Longll;#defineMem (a) memset (A,0,sizeof (a))#definePB Push_back#defineFi first#defineSe Second#defineMP Make_pairinline ll read () {ll x=0, f=1; CharCh=GetChar (); while(ch<'0'|| Ch>'9') { if(ch=='-') f=-1; CH=GetChar (); } while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; CH=GetChar (); } returnx*F;}//****************************************Const intn=100000+ -;Constll inf = 1ll<< A;Const intMod=1000000007;intAns,a[n],h[n],n;intDp[n];intMain () {ans=-1; scanf ("%d",&N); for(intI=1; i<=n;i++) {scanf ("%d",&A[i]); } for(intI=1; i<=n;i++) {H[a[i]]++; if(h[a[i]-1]) dp[a[i]]=dp[a[i]-1]+1; Elsedp[a[i]]=1; Ans=Max (Ans,dp[a[i]]); } cout<<n-ans<<Endl; return 0;Code
Codeforces Round #335 (Div. 2) C. Sorting Railway Cars Continuous lis