2016 Winter Training Day #1_D題_codefcrces 432A(貪心)


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 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
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;
}















注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
粤ICP备14056181号  © 2014-2021 ITdaan.com