aboutsummaryrefslogtreecommitdiff
path: root/codeforces/MakeItIncreasing/MakeItIncreasing.cpp
blob: 987ef047910e99584d407b0f723bcbe45051fd8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<bits/stdc++.h>
using namespace std;
int main() {
  int tt;
  cin >> tt;
  while(tt--) {
    int n;
    int ans = 0;
    cin >> n;
    vector<int> v(n);
    for(auto &x : v) cin >> x;
    for(int i = n - 1; i > 0; i--) {
      while(v[i] <= v[i-1] && v[i - 1] > 0) {
        v[i-1] = v[i-1] / 2;
        ans++;
      }
      if(v[i] == v[i-1]) {
        ans = -1;
        break;
      }
    }
    cout << ans << endl;
  }
}