Codeforces Round #246 (Div. 2) A. Choosing Teams

排个序,对每个队的尾判断一下,贪心水题

#include<cstdio>
#include<algorithm>
using namespace std;
int a[2010];
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
    sort(a,a+n);
    int num=0;
    for(int i=2;i<n;i+=3)
    {
        if((a[i]+k)<=5)
        num++;
    }
    printf("%d\n",num);
    return 0;
}

你可能感兴趣的:(Codeforces Round #246 (Div. 2) A. Choosing Teams)