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;
    }
}
上一篇:java流程控制


下一篇:C. The Football Season (枚举) ( Codeforces Round #592 (Div. 2) )