mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-24 00:48:47 +00:00
B - Make It Increasing
https://codeforces.com/contest/1675/submission/155955441
This commit is contained in:
parent
ff26a578b1
commit
bdc65eecf9
47
Codeforces/1675/B/B.cpp
Normal file
47
Codeforces/1675/B/B.cpp
Normal file
@ -0,0 +1,47 @@
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
#include <limits>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 35;
|
||||
|
||||
int t, n, a[N], ans;
|
||||
bool flag;
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
ans = 0;
|
||||
flag = false;
|
||||
|
||||
cin >> n;
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
cin >> a[i];
|
||||
}
|
||||
|
||||
a[n + 1] = std::numeric_limits<int>::max();
|
||||
|
||||
for (int i = n; i; i--) {
|
||||
while (a[i] >= a[i + 1]) {
|
||||
a[i] = std::floor(1.0 * a[i] / 2);
|
||||
ans++;
|
||||
}
|
||||
|
||||
if (a[i] == 0 && i != 1) {
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
cout << (flag ? -1 : ans) << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user