【cf432A】Choosing Teams

描述 Description

The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has n students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.

The head of the SSU OPTC is recently gathering teams to participate in the world championship. Each team must consist of exactly three people, at that, any person cannot be a member of two or more teams. What maximum number of teams can the head make if he wants each team to participate in the world championship with the same members at least k times?

输入格式 InputFormat

The first line contains two integers, n and k (1 ≤ n ≤ 2000; 1 ≤ k ≤ 5). The next line contains n integers: y1, y2, …, yn (0 ≤ yi ≤ 5), where yi shows the number of times the i-th person participated in the ACM ICPC world championship.

输出格式 OutputFormat

Print a single number — the answer to the problem.

样例输入 SampleInput

5 2
0 4 5 1 0

样例输出 SampleOutput

1


Codeforces 432A


代码 Code

水。

#include <stdio.h>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdlib>
using namespace std;
int a[2001];
int i,j,t,n,m,l,r,k,z,y,x;
int main()
{
    scanf("%d%d",&n,&k);
    for (i=1;i<=n;i++) scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    z=0;
    for (i=3;i<=n;i+=3)
    {
        if (a[i]+k<=5) z++;
        else break;
    }
    printf("%d\n",z);
    return 0;
}