CF#246 (Div. 2) A.

来源:互联网 发布:php前端网站 编辑:程序博客网 时间:2024/05/21 11:57
A. Choosing Teams
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
题目链接:http://codeforces.com/contest/432/problem/A

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?

Input

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.

Output

Print a single number — the answer to the problem.

Sample test(s)
input
5 20 4 5 1 0
output
1
input
6 40 1 2 3 4 5
output
0
input
6 50 0 0 0 0 0
output
2
Note

In the first sample only one team could be made: the first, the fourth and the fifth participants.

In the second sample no teams could be created.

In the third sample two teams could be created. Any partition into two teams fits.




解题思路:

  题意是没人最多参加5次Final,现在给出n个人参加过的次数,要求选择三个人的队伍至少原班人马参加k次Final,问能组多少个队。

如果当前次数加上k后大于5的话舍去·····这样的参加不了k次Final·····剩下的计数,三个一组。


完整代码:

#include <functional>#include <algorithm>#include <iostream>#include <fstream>#include <sstream>#include <iomanip>#include <numeric>#include <cstring>#include <climits>#include <cassert>#include <complex>#include <cstdio>#include <string>#include <vector>#include <bitset>#include <queue>#include <stack>#include <cmath>#include <ctime>#include <list>#include <set>#include <map>using namespace std;#pragma comment(linker, "/STACK:102400000,102400000")typedef long long LL;typedef double DB;typedef unsigned uint;typedef unsigned long long uLL;/** Constant List .. **/ //{const int MOD = int(1e9)+7;const int INF = 0x3f3f3f3f;const LL INFF = 0x3f3f3f3f3f3f3f3fLL;const DB EPS = 1e-9;const DB OO = 1e20;const DB PI = acos(-1.0); //M_PI;int main(){    #ifdef DoubleQ    freopen("in.txt","r",stdin);    #endif    int n , k ;    while(~scanf("%d%d",&n,&k))    {        int t , cnt = 0 , res = 0;        for(int i = 0 ; i < n ; i++)        {            scanf("%d",&t);            if(t + k <= 5)                cnt ++;            if(cnt == 3)            {                res ++;                cnt = 0;            }        }        printf("%d\n",res);    }}


0 0
原创粉丝点击