dark-Matter

https://codeforces.com/contest/1367/problem/F2

Jun 16th, 2020
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.47 KB | None | 0 0
  1. from sys import stdin, stdout
  2.  
  3. R = lambda : stdin.readline().strip()
  4. RL = lambda : list(map(int, R().split(' ')))
  5.  
  6. output = lambda x: stdout.write(str(x) + '\n')
  7.  
  8. MX = 10**9 + 5
  9.  
  10. for tc in range(int(R())):
  11.     n = int(R())
  12.     a = RL()
  13.     b = []
  14.     for i in range(n):
  15.         b.append([a[i], i])
  16.     b.sort()
  17.     dp = n*[1]
  18.     for i in range(1,n):
  19.         if b[i][1]>b[i-1][1]:
  20.             dp[i] = max(dp[i], dp[i-1]+1)
  21.     print(n-max(dp))
  22.     print(dp)
Add Comment
Please, Sign In to add comment