codeforces-432A. Choosing Teams-题解

题目:

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.

eg:

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

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的数有多少,遍历即可。(与3的关系)

mycode:

#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int a[100000];
int main()
{
	int n,k,w,sum=0,ans=0;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>w;
		a[i]=w+k;
	}
	for(int i=0;i<n;i++){
		if(a[i]<=5)
			sum++;
		if(sum==3){
			sum=0;
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

不要想太多,没有排序,提示是骗人的!!!

posted @   金鳞踏雨  阅读(15)  评论(0编辑  收藏  举报  
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
点击右上角即可分享
微信分享提示