ashutosh_sundriyal

BALASEQ IUPC Solution (Codechef)

Jan 7th, 2020
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;    
  3. int main(){
  4.     long long i,j,ans=0,n,a[200005],b[200005],maxx=1;
  5.     map<long,long> c;
  6.     cin>>n;
  7.     for(i=0;i<n;i++)
  8.     cin>>a[i];
  9.     for(i=0;i<n;i++){
  10.         cin>>b[i];
  11.         c[b[i]]=i;
  12.         b[i]=i;
  13.     }
  14.     for(i=0;i<n;i++){
  15.         a[i]=c[a[i]];
  16.     }
  17.     ans=1;
  18.     for(i=0;i<n-1;i++){
  19.         if(a[i+1]>a[i]){
  20.             ans++;
  21.             maxx=max(maxx,ans);
  22.         }
  23.         else{
  24.             ans=1;
  25.         }
  26.     }
  27.     cout<<n-maxx<<endl;
  28. }
Add Comment
Please, Sign In to add comment