A. Powered Addition【greedy】

insert image description here
To increase, each number must be greater than or equal to the previous maximum value. Save the largest difference.
Then find its binary digits, which is the optimal solution.

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int a[N],t,n;
int main(void)
{
    
    
    cin>>t;
    while(t--)
    {
    
    
        cin>>n;
        for(int i=1;i<=n;i++) cin>>a[i];
        int ans=0,maxv=a[1];
        for(int i=2;i<=n;i++)
        {
    
    
            ans=max(ans,maxv-a[i]);
            maxv=max(maxv,a[i]);
        }
        if(ans<=0) puts("0");
        else
        {
    
    
            int cnt=0;
            while(ans) ans=ans>>1,cnt++;
            cout<<cnt<<endl;
        }
    }
    return 0;
}

Guess you like

Origin blog.csdn.net/qq_46527915/article/details/123670894