fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes here
  6. int t;
  7. cin>>t;
  8. vector<int> arr(30);
  9. while(t--){
  10. int n;
  11. cin>>n;
  12. for(int i=0;i<n;i++) cin>>arr[i];
  13. int count = 0;
  14. bool pos = true;
  15. for(int i=n-2;i>=0;i--){
  16. while(arr[i] >= arr[i+1]){
  17. if(arr[i] == 0){
  18. pos = false;
  19. break;
  20. }
  21. count++;
  22. arr[i] /= 2;
  23. }
  24. }
  25.  
  26. if(pos) cout<<count<<"\n";
  27. else cout<<-1<<"\n";
  28.  
  29. }
  30. return 0;
  31. }
Success #stdin #stdout 0s 5324KB
stdin
7
3
3 6 5
4
5 3 2 1
5
1 2 3 4 5
1
1000000000
4
2 8 7 5
5
8 26 5 21 10
2
5 14
stdout
2
-1
0
0
4
11
0