429A. Generous Kefa
来源:互联网 发布:数据结构c语言课程设计 编辑:程序博客网 时间:2024/06/08 11:39
One day Kefa found n baloons. For convenience, we denote color ofi-th baloon assi — lowercase letter of the Latin alphabet. Also Kefa hask friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give outall 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.
The first line contains two integers n andk (1 ≤ n, k ≤ 100) — the number of baloons and friends.
Next line contains string s — colors of baloons.
Answer to the task — «YES» or «NO» in a single line.
You can choose the case (lower or upper) for each letter arbitrary.
4 2aabb
YES
6 3aacaab
NO
In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and4-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».
import java.util.Scanner;public class CF_429B {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int n = sc.nextInt();int k = sc.nextInt();String str = sc.next();char[] a = str.toCharArray();int m=0,flag = 0;int[] z = new int[26];for(int i=0;i<n;i++) {m = a[i]-97;z[m]++;if(z[m]>k) {System.out.println("NO");flag = 1;return ;}}if(flag==0)System.out.println("YES");}}
- 429A. Generous Kefa
- Codeforces 429 A. Generous Kefa
- Codeforces-429-2-A Generous Kefa
- A. Generous Kefa
- codeforces 841A Generous Kefa
- codeforces 841A Generous Kefa
- Codeforces Round #429 (Div. 2) 841A Generous Kefa(水)
- Codeforces Round #429 (Div. 2):A. Generous Kefa
- Codeforces Round #429 (Div. 2) | A. Generous Kefa
- A. Generous Kefa(Round #429 (Div. 2))
- Generous Kefa
- Generous Kefa CodeForces
- CF Generous Kefa(水)
- Codeforces 841 Generous Kefa(模拟)
- A. Kefa and First Steps
- coderforce 580A Kefa and First Steps
- CodeForces 580A Kefa and First Steps
- Codeforces 580A Kefa and First Steps
- B. Godsend
- Java中转换字符串编码
- 传感器项目框架1
- Android Studio中的神操作
- MAVEN配置pom.xml名词解释
- 429A. Generous Kefa
- uva 11582 快速幂 Fibonacci循环节
- CentOS 6使用openssl搭建根CA
- 01背包问题之二 (动态规划(DP))
- Lua5.3 虚拟机指令分析(二)赋值指令
- 第二章:2.3 卷积定义(卷积积分与卷积和)
- HTML---第一天内容
- 不信...如果...
- 动态规划、递归:word-break II