Advertisement
Saleh127

CF 606C

Oct 14th, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. ///CF 606C
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. #define ll long long
  5. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  6. int a[100050];
  7. int main()
  8. {
  9. int n;
  10. int i,j,k,l,max;
  11. while(~scanf("%d",&n))
  12. {
  13. for(i = 1; i <= n; i++)
  14. {
  15. scanf("%d",&k);
  16. a[k] = i;
  17. }
  18. max = 1;
  19. for(i = 1; i <= n-1; i+=l)
  20. {
  21. l=1;
  22. for(j = i+1; j <= n; j++)
  23. {
  24. if(a[j]>a[j-1])
  25. {
  26. l++;
  27. }
  28. else break ;
  29. }
  30. if(l>max)
  31. {
  32. max = l;
  33. }
  34. }
  35. printf("%d\n",n-max);
  36. }
  37. return 0;
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement