其他分享
首页 > 其他分享> > Codeforces Global Round 17 E. AmShZ and G.O.A.T.

Codeforces Global Round 17 E. AmShZ and G.O.A.T.

作者:互联网

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int t,n,a[N];

int main(){
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);for(int i=1;i<=n;i++)scanf("%d",&a[i]);
        int ans=0;
        for(int i=1;i<=n;i++){
            if(a[i]==a[i-1]) continue;
            int cnt=0,pos=i;
            while(pos<=n){
                pos=lower_bound(a+1+pos,a+1+n,2*a[pos]-a[i])-a;
                cnt++;
            }
            ans=max(ans,cnt);
        }
        cout<<n-ans<<endl;
    }
}

标签:cnt,int,scanf,Global,Codeforces,pos,while,AmShZ,ans
来源: https://blog.csdn.net/weixin_45714303/article/details/122784282