B. Equalize
与数组的原始顺序无关,直接排序,然后用双指针滑动范围a[r]-a[l]小于n
#include<bits/stdc++.h>
#define int long long
using namespace std;
void solve(){
int n;
cin>>n;
set<int>st;
for(int i=1;i<=n;i++){
int x;
cin>>x;
st.insert(x);
}
vector<int>a(st.begin(),st.end());
int m=a.size();
int ans=1;
int l=0,r=0;
while(r<m){
while(r<m&&a[r]-a[l]<n)r++;
ans=max(ans,r-l);
l++;
}
cout<<ans<<"\n";
}
signed main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t=1;
cin>>t;
for(int i=1;i<=t;i++)solve();
return 0;
}
标签:int,Codeforces,long,st,Div,924,Round
From: https://www.cnblogs.com/yufan1102/p/18014455