fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. const int Mod=998244353;
  5. const ll INF = -10000000000000;
  6.  
  7. void solve() {
  8. int n;
  9. cin >> n;
  10. vector<int> a(n);
  11. for(int i=0;i<n;i++) cin >> a[i];
  12. int ans =n;
  13. for(int i=0;i<n;i++){
  14. int cnt = 0;
  15. for(int j=i+1;j<n;j++){
  16. if(a[j]>a[i]) cnt++;
  17. }
  18. ans = min(ans,i+cnt);
  19. }
  20. cout << ans << '\n';
  21. }
  22.  
  23. int main(){
  24. ios::sync_with_stdio(false);
  25. cin.tie(nullptr);
  26.  
  27. int t;
  28. cin >> t;
  29. while (t--) solve();
  30.  
  31.  
  32. return 0;
  33. }
  34.  
Success #stdin #stdout 0s 5320KB
stdin
6
7
3 6 4 9 2 5 2
5
5 4 4 2 2
8
2 2 4 4 6 6 10 10
1
1000
9
6 8 9 10 12 9 7 5 4
7
300000000 600000000 400000000 900000000 200000000 400000000 200000000
stdout
2
0
6
0
4
2