Codeforces 841A - Generous Kefa

题目链接:http://codeforces.com/problemset/problem/841/A

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».

题解:水水

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <string>
 5 #include <algorithm>
 6 #include <cmath>
 7 using namespace std;
 8 const int N=10005;
 9 char a[101];
10 int main()
11 {
12     int n,k;
13     while(cin>>n>>k){
14         for(int i=0;i<n;i++)
15             cin>>a[i];
16         sort(a,a+n);
17         int m=0,t=1;
18         for(int i=1;i<n;i++){
19             if(a[i]==a[i-1]){
20                 t++;
21                 if(t>m) m=t;
22             }
23             else t=1;
24         }
25         if(m>k) cout<<"NO"<<endl;
26         else cout<<"YES"<<endl;
27     }
28     return 0;
29 }
时间: 2024-10-13 11:28:07

Codeforces 841A - Generous Kefa的相关文章

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 o

Codeforces 841A 841B题解

此文为博主原创题解,转载时请通知博主,并把原文链接放在正文醒目位置. A. Generous Kefa B. Godsend 两道水题... A - 题目大意:把n个字母分配给k个人,如果一个人得到了两个或两个以上的相同字母,就会不开心,否则会开心(没有分配到字母也算开心).请问能否找到一个合理的分配方案,使得每一个人都开心.如果能,输出YES,否则输出NO. 分析: 抽屉原理.如果任意一种字母的出现次数大于k,输出NO,否则输出YES. AC代码: 1 #include<cstdio> 2

[2016-03-23][codeforces][580][A][Kefa and First Steps]

时间:2016-03-23 13:04:56 星期三 题目编号:[2016-03-23][codeforces][580][A][Kefa and First Steps] 题目大意:求最长上升子串 #include <cstdio> using namespace std; int a[100000 + 100]; int main(){ int n; scanf("%d",&n); for(int i = 0 ;i < n ;++i) scanf(&quo

codeforces 580D:Kefa and Dishes

Description When Kefa came to the restaurant and sat at a table, the waiter immediately brought him the menu. There were n dishes. Kefa knows that he needs exactly m dishes. But at that, he doesn't want to order the same dish twice to taste as many d

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++)

CodeForce 841 A/B/C 解题报告

A Generous Kefa 题目大意: 一共有n个物品,k个人.每一个物品都有自己的颜色,颜色相同意味着同一件物品.现在要把所有的物品分出去,如果有人拿到了相同的物品就会不高兴.问是否存在方案使得每一个人都高兴? 大致思路: 给每一个物品开一个桶,然后按照顺序把物品放到桶里,最后扫一遍桶,如果有桶里物品的数目大于人数,那么根据抽屉原理可以知道必然有有人会拿到相同的物品 代码: 1 #include<bits/stdc++.h> 2 using namespace std; 3 int ma

集训队寒假集训第二场补题题解

补题什么的待填坑... A - Generous Kefa (语法基础) 直接开桶看看有没有超过三个的,因为题目明确提出没有气球也是可以的 代码 #include <bits/stdc++.h> using namespace std; int bk[123213]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,k; cin>>n>>k; string a; cin>&g

寒假集训第二场

整理人:贺振原 A - Generous Kefa (1) 马鸿儒 (2) 朱远迪 B - Godsend (1) 马鸿儒 (2) 朱远迪 C - Leha and Function D - Leha and another game about graph E - New Year and Ancient Prophecy F - New Year and Days (1) 马鸿儒 (2) 朱远迪 G - New Year and Domino H - New Year and Old Pro

dp + 状态压缩 - Codeforces 580D Kefa and Dishes

Kefa and Dishes Problem's Link Mean: 菜单上有n道菜,需要点m道.每道菜的美味值为ai. 有k个规则,每个规则:在吃完第xi道菜后接着吃yi可以多获得vi的美味值. 问:最多可以获得多少美味值? (1≤m≤n≤18,0≤k≤n∗(n−1)) analyse: 经典的状压DP. 由于最多18道菜,可用一个数s(s<=2^18)来唯一标识一种状态. 对于一个状态s,枚举两个位置i和j:i从已选择的菜中选定,j从未选择的菜中选定. 下一个状态ss的就是:吃完i后接着