Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define INF 1145141919810364364
#define REP(i,n) for (int i=0;i<(n);i++)
typedef pair<int,int> P;
int dp[30100]={};
signed main() {
int N; cin>>N;
vector<int> c(N);
for(int i=0;i<N;i++) cin>>c[i];
for(int i=0;i<N;i++) {
dp[i]=1;
for(int j=0;j<i;j++){
if(c[j]<=c[i]) dp[i]=max(dp[i],dp[j]+1);
}
}
sort(dp,dp+N);
reverse(dp,dp+N);
cout<<N-dp[0]<<endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment