题目链接: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 }