Untitled

mail@pastecode.io avatar
unknown
plain_text
11 days ago
980 B
1
Indexable
Never
#pragma GCC optimize("O2,no-stack-protector,unroll-loops")
#define ll long long
#define pb push_back
#define ipar(arr, n) vector<ll> arr(n); for(int i=0;i<n;i++) cin>>arr[i];
#include <cmath>
#include <bits/stdc++.h>
#define pii pair<int, int>;
#define pll pair<ll, ll>;
using namespace std;


void solve(){
    ll n;cin>>n;
    set<ll>s;
    for(ll i=0;i<n;i++){
        ll inp; cin>>inp;
        s.insert(inp);
    }
    vector<ll>arr;
    for(auto it=s.begin();it!=s.end();it++) arr.pb(*it);
    ll l=0,r=1;
    ll res=INT_MIN;
    ll count=1;
    ll size=arr.size();
    while(l<size &&  r<size){
        if(arr[r]-arr[l]<=n-1) {
            count++;
            r++;
        }
        else {
            l++;
            count--;
        }
        res=max(res,count);
    }
    cout<<max((ll)1,res)<<"\n";
}


signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int t;
	cin>>t;
	while(t--) solve();
}
Leave a Comment