Description
The Saratov state University Olympiad Programmers Training Center (SSU OPTC) has n students. For each student know the number of times he/she have 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 of the team must consist of exactly three people, at this, any person cannot is a member of or more teams. What maximum number of teams can the head do if he wants each team to participate in the world Championship with the SAM E members at least k times?
Input
The first line contains the integers, n and k(1≤ n ≤ 2000; 1≤ K ≤5). The next line contains n integers: y1, y2, ..., y N(0≤ yi ≤5), where yi shows the number of times th E i-th person participated in the ACM ICPC World Championship.
Output
Print a single number-the answer to the problem.
Sample Input
Input
5 2
0 4 5) 1 0
Output
1
Input
6 4
0 1 2 3 4 5
Output
0
Input
6 5
0 0 0 0 0 0
Output
2
Hint
In the first sample only one team could is made:the first, the fourth and the fifth participants.
In the second sample no teams could is created.
In the third sample, teams could be created. Any partition into and teams fits.
#include <cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespacestd;inta[ -+Ten];intMain () {intI,j,n,add,ans; while(SCANF ("%d%d", &n,&add)! =EOF) { if(add>5) {printf ("0\n");Continue;} Ans=0; for(i=0; i<n;i++) {scanf ("%d",&A[i]); A[i]+=add; } sort (A,a+N); for(i=0; i<n;i++) { if(a[i]<=5) ans++; Else Break; } printf ("%d\n", ans/3); } return 0;}
View Code
Codeforces 432A choosing Teams (water)