Codeforces Round #544 (Div. 3) C. Balanced Team

版权声明:版权声明,使用请说明出处 https://blog.csdn.net/qq_41835683/article/details/88958323

题解,题意都在代码里.. 

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define int long long 
const int maxn=2e5+5;

int s[maxn];
signed main(){
    /*
        It means that the programming skill of each pair of students in a created team should differ by no more than 5.
        Print one integer — the maximum possible number of students in a balanced team.
    */
    int n;cin>>n;
    for(int i=1;i<=n;i++)cin>>s[i];
    sort(s+1,s+n+1);
    
    int ans=0;
    for(int i=1;i<=n;i++){//1 2 10 12 15 17 18
        int temp=upper_bound(s+1,s+n+1,s[i]+5)-s;//for the first indext that > s[i] + 5 
        ans=max(ans,temp-i);
    }
    cout<<ans<<endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41835683/article/details/88958323