【codeforces841A】Generous Kefa

原题#

A. Generous Kefa
time limit per test:
2 seconds
memory limit per test:
256 megabytes

input:standard input

output:standard output

     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#

input1

4 2
aabb

output1

YES

input2

6 3
aacaab

output2

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

题目大意#

给一串包含小写字母的字符串,每个字符代表不同颜色的气球,再给出一个人数,问能否把气球发完并保证不存在一个人拿2个相同颜色的气球。

解法#

水题:只要保证数量最多的那种颜色的气球不超过人数即可

代码#


#include<iostream>
#include<cstdio>
#include<string>
#define MAXX 
using namespace std;
int g_n,g_k,g_cnt;
int a[30];
int main(){
    string ch;
    scanf("%d%d",&g_n,&g_k);
    cin>>ch;
    int len=ch.size();
    for(int i=0;i<len;i++) 
        a[ch[i]-'a'+1]++;
    for(int i=1;i<=26;i++)
        if(a[i]>g_k){
            cout<<"NO";
            return 0;
        }
    cout<<"YES";
    return 0;
}
posted @   bbqub  阅读(339)  评论(0编辑  收藏  举报
编辑推荐:
· .NET制作智能桌面机器人:结合BotSharp智能体框架开发语音交互
· 软件产品开发中常见的10个问题及处理方法
· .NET 原生驾驭 AI 新基建实战系列:向量数据库的应用与畅想
· 从问题排查到源码分析:ActiveMQ消费端频繁日志刷屏的秘密
· 一次Java后端服务间歇性响应慢的问题排查记录
阅读排行:
· 互联网不景气了那就玩玩嵌入式吧,用纯.NET开发并制作一个智能桌面机器人(四):结合BotSharp
· Vite CVE-2025-30208 安全漏洞
· 《HelloGitHub》第 108 期
· MQ 如何保证数据一致性?
· 一个基于 .NET 开源免费的异地组网和内网穿透工具
点击右上角即可分享
微信分享提示
CONTENTS