码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-08-19 17:08:19      阅读:225      评论:0      收藏:0      [点我收藏+]

标签:integer   upper   sub   ecif   contains   wan   ica   std   ext   

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 2
aabb
Output
YES
Input
6 3
aacaab
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 }

 

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

标签:integer   upper   sub   ecif   contains   wan   ica   std   ext   

原文地址:http://www.cnblogs.com/Egoist-/p/7396783.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!