Codeforces Round #429 (Div. 2) 841A. Generous Kefa(签到题)

A. Generous Kefa

One day Kefa found n baloons. For convenience, we denote color of i-th baloon as si — lowercase letter of the Latin alphabet. Also Kefa has k friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset — print ?YES?, if he can, and ?NO?, otherwise. Note, that Kefa‘s friend will not upset, if he doesn‘t get baloons at all.

Input

The first line contains two integers n and k (1?≤?n,?k?≤?100) — the number of baloons and friends.

Next line contains string s — colors of baloons.

Output

Answer to the task — ?YES? or ?NO? in a single line.

You can choose the case (lower or upper) for each letter arbitrary.

Examples

Input

4 2aabb

Output

YES

Input

6 3aacaab

Output

NO

Note

In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second.

In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is ?NO?.



题意:每个人能不能分到均不相同的颜色气球……思路很简单,只要数目最多的颜色不超过人数就好了……(窝现在也就做做签到题了orz(○| ̄|_  ) )

感觉用map比较好处理……就懒懒の用了map……2333333

 1 #include<iostream>
 2 #include<algorithm>
 3 #include<string>
 4 #include<string.h>
 5 #include<map>
 6 using namespace std;
 7 int n, k;
 8 map<char, int>p;
 9 char s;
10 int main()
11 {
12     while (cin >> n >> k)
13     {
14         p.clear();
15         for (int i = 0; i < n; i++)
16         {
17             cin >> s;
18             p[s]++;
19         }
20         map<char,int>::iterator ite;
21         int maxx = 0;
22         for (ite = p.begin(); ite != p.end(); ite++)
23         {
24             if (ite->second > maxx)
25                 maxx = ite->second;
26         }
27         if (maxx > k) cout << "NO" << endl;
28         else cout << "YES" << endl;
29     }
30     return 0;
31 }
时间: 2024-10-13 20:21:39

Codeforces Round #429 (Div. 2) 841A. Generous Kefa(签到题)的相关文章

CodeForces 840B - Leha and another game about graph | Codeforces Round #429(Div 1)

思路来自这里,重点大概是想到建树和无解情况,然后就变成树形DP了- - /* CodeForces 840B - Leha and another game about graph [ 增量构造,树上差分 ] | Codeforces Round #429(Div 1) 题意: 选择一个边集合,满足某些点度数的奇偶性 分析: 将d = 1的点连成一颗树,不在树上的点都不连边. 可以发现,当某个节点u的所有子节点si均可操控 (u, si) 来满足自身要求 即整棵树上至多只有1个点不满足自身要求,

CodeForces 840A - Leha and Function | Codeforces Round #429 (Div. 1)

/* CodeForces 840A - Leha and Function [ 贪心 ] | Codeforces Round #429 (Div. 1) A越大,B越小,越好 */ #include <bits/stdc++.h> using namespace std; const int N = 2e5+5; int a[N], b[N], c[N], n; int aa[N], bb[N]; bool cmp1(int x, int y) { return a[x] > a[y

Codeforces Round #259 (Div. 2) (简单模拟实现题)

题目链接:http://codeforces.com/problemset/problem/454/A A. Little Pony and Crystal Mine time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Twilight Sparkle once got a crystal from the Crystal Mine

Codeforces Round #260 (Div. 2) A. Laptops(简单题)

题目链接:http://codeforces.com/problemset/problem/456/A A. Laptops time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output One day Dima and Alex had an argument about the price and quality of laptops.

Codeforces Round #423 (Div. 2) D. High Load(构造题)

题目链接:Codeforces Round #423 (Div. 2) D. High Load 题意: 给你一个数n和k,让你构造出一颗树,有k个叶子节点,使得这棵树的任意两个点的距离的最大值最小. 题解: 显然要使得这棵树的任意两个点的距离的最大值最小,每个点离树根越近越好. 然后要求有k个叶子节点,所以我就任意选一个点为根,然后构成一棵m叉的树就行了. 最大距离的最小值就是离根最远的和最近的加一加就行了. 1 #include<cstdio> 2 #define F(i,a,b) for

Codeforces Round#429(Div.2)

A. Generous Kefa 如果有字母的个数大于k则NO #include<bits/stdc++.h> using namespace std; int arr[28],n,k; string str; int main(){ cin>>n>>k; cin>>str; for(int i = 0;i<str.length();i++){ arr[(int)(str[i]-'a')]++; } for(int i = 0;i<26;i++)

【推导】【DFS】Codeforces Round #429 (Div. 1) B. Leha and another game about graph

题意:给你一张图,给你每个点的权值,要么是-1,要么是1,要么是0.如果是-1就不用管,否则就要删除图中的某些边,使得该点的度数 mod 2等于该点的权值.让你输出一个留边的方案. 首先如果图内有-1,那么必有解.否则如果初始不合法的点数为偶数,那么必有解,否则无解.因为删一条边,要么使图中不合法的点数+2,要么不变,要么-2. 如果有解,构造图的任意一个生成树,如果有-1,就让-1为根,否则任意结点为根.然后从叶子向根定每个点的入度数,由于自底向上,一个结点的儿子边都被处理完后,只需要决定父边

【CodeForces】841C. Leha and Function(Codeforces Round #429 (Div. 2))

[题意]定义函数F(n,k)为1~n的集合中选择k个数字,其中最小数字的期望. 给定两个数字集A,B,A中任意数字>=B中任意数字,要求重组A使得对于i=1~n,sigma(F(Ai,Bi))最大. [算法]数学结论+数学期望+排序 [题解]很无奈,这题放在div2 C,难以推导的期望公式,广为人知的结论,容易观察样例得出的做法,都体现了这道题的不合理性. F(n,k)=(n+1)/(k+1) 公式推导可能触及我的知识盲区了QAQ 得到公式后,显然要求k尽可能小,n尽可能大,经验告诉我们随着两数

Codeforces Round #429 (Div. 2)ABC

A: 题意:n个东西,k个朋友,全部给朋友,每个朋友不可以拿同样的,问是否可行 1 #include<bits/stdc++.h> 2 using namespace std; 3 4 map<char ,int >ma; 5 int main(){ 6 int n,k; 7 cin>>n>>k; 8 string s; 9 cin>>s; 10 for(int i=0;i<n;i++){ 11 ma[s[i]]++; 12 if(ma[s