2016 Winter Training Day #1_D题_codefcrces 432A(贪心)

来源:互联网 发布:ubuntu 16.04 精简下载 编辑:程序博客网 时间:2024/05/16 09:07
A. Choosing Teams
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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次ACM ICPC world programming championship(- -不是2次咩),每个队伍要求三人参赛,每个人不得加入两个队伍。给出n和k,n为人数,k为参加比赛的次数。问有多少个队可以完成k次参赛。

思路:简单贪心,将n个人已经参加比赛的次数升序排列,则越靠前的人可以继续参加的比赛越多。(注意是3人组队,所以只需考察第3,,6,9......等下标为3的倍数的人+k后能否 <= 5 就可以了)。

代码:

#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <vector>#include <queue>#include <stack>#include <cmath>#include <map>#include <set>using namespace std;const int INF = 0x7fffffff;int a[2500];bool cmp(int a, int b){    return a < b;}int main(){    int n, k;    cin >> n >> k;    for(int i = 0; i < n; ++i)        cin >> a[i];    sort(a, a+n, cmp);    int ans = 0;    for(int i = 2; i < n; i+=3)    {        if(a[i] + k <= 5)            ans++;        else            break;    }    cout << ans << endl;    return 0;}


0 0
原创粉丝点击