CF1338A Powered Addition

思路

问题等价于找到一个\(b\)数组,使得

$b_i$+$a_i$ $>=$ $b_i{_-}{_1}$ + $a_i{_-}{_1}$
移项得
$b_i$ $>=$ $b_i{_-}{_1}$ + $a_i{_-}{_1}$ - $a_i$
我们要使得$b$数组最小化,即$b_i = max(0, b_i{_-}{_1} + a_i{_-}{_1} - a_i)$

ac代码

#include <bits/stdc++.h>

using namespace std;
using i64 = long long;
const i64 inf = 1e18;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
const int N = 1e6 + 10;

void solve() {
    int n;
    cin >> n;
    vector<i64> a(n + 1), b(n + 1, 0);
    i64 ans = 0;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 2; i <= n; i++) {
        b[i] = max(0ll, b[i - 1] + a[i - 1] - a[i]);
        if (b[i]) ans = max(ans, __lg(b[i]) + 1);
    }
    cout << ans << endl;
}   

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cout.tie(0);

    int t = 1;
    cin >> t;
    while (t --) solve();

    return 0;
}
posted @ 2024-01-18 22:21  jvdyvan  阅读(6)  评论(0)    收藏  举报