守卫问题The Festive Evening



It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here are not supposed to be disclosed to the general public: the information can cause discord in the kingdom of Sweetland in case it turns out to reach the wrong hands. So it's a necessity to not let any uninvited guests in.

There are 26 entrances in Jelly Castle, enumerated with uppercase English letters from A to Z. Because of security measures, each guest is known to be assigned an entrance he should enter the castle through. The door of each entrance is opened right before the first guest's arrival and closed right after the arrival of the last guest that should enter the castle through this entrance. No two guests can enter the castle simultaneously.

For an entrance to be protected from possible intrusion, a candy guard should be assigned to it. There are k such guards in the castle, so if there are more than k opened doors, one of them is going to be left unguarded! Notice that a guard can't leave his post until the door he is assigned to is closed.

Slastyona had a suspicion that there could be uninvited guests at the evening. She knows the order in which the invited guests entered the castle, and wants you to help her check whether there was a moment when more than k doors were opened.

Input

Two integers are given in the first string: the number of guests n and the number of guards k (1 ≤ n ≤ 106, 1 ≤ k ≤ 26).

In the second string, n uppercase English letters s1s2... sn are given, where si is the entrance used by the i-th guest.

Output

Output «YES» if at least one door was unguarded during some time, and «NO» otherwise.

You can output each letter in arbitrary case (upper or lower).

Examples
Input
5 1
AABBB
Output
NO
Input
5 1
ABABB
Output
YES



思路 :
枚举每一个时间点求公用的交叉段的个数,然后求出最大的个数,与守卫的个数来比较 。
*/
#if 0
#include<bits/stdc++.h>
using namespace std;
int ans;
int main()
{
 int t[30][2],n,gar,num=0,max=0;
 
 char c[1000006] ;
  cin>>n>>gar;
 
 for(int i=0; i<n; i++)
  cin>>c[i];
 
 while(num!=n) 
 {
  int k1,k2;
  char cc; 
  
  for(int i=0; i<n; i++)
  {
   if(c[i]!='0')
   {
    cc=c[i];
    k1=i;
    t[ans++][0]=i;
   break;
   }
  }
  
  for(int i=n-1; i>=0; i--)
  {
   if(c[i]==cc)
   {
    k2=i;
    t[ans-1][1]=i;
    break;
   }
  }
  
  for(int i=k1; i<=k2; i++)
  {
   if(c[i]==cc)
   {
    num++;
    c[i]='0';
   }
  }
  
 }
 
 
 for(int i=0; i<n; i++)
 {  
  int cnt=0;
  for(int j=0; j<ans; j++)
  {
   if(t[j][0]<=i && t[j][1]>=i)
   {
    cnt++;
   }
  }
  
  if(cnt>max)
   max=cnt;
 }
 
 if(max>gar)
  cout<<"YES"<<endl;
 else
  cout<<"NO"<<endl; 
 
}
#endif


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
As an AI language model, I don't have personal experiences. However, I can provide you with an article about the party's twenty great experiences. Parties are a great way to let loose and have fun with friends and family. There are so many things you can do at a party that can make it a memorable experience. Here are twenty great experiences that can make any party an unforgettable one. 1. Have a theme: Having a theme for the party can make it more exciting and fun. It can be anything from a 70s disco theme to a Hawaiian luau theme. The possibilities are endless. 2. Decorate the space: Decorating the space can make it more festive and inviting. Balloons, streamers, and banners are just some of the items that can be used to decorate the space. 3. Play games: Playing games can be a great way to break the ice and get everyone involved. Some popular games include charades, Pictionary, and beer pong. 4. Have a photo booth: Setting up a photo booth with fun props can be a great way to capture memories and create some hilarious photos. 5. Have a karaoke session: Karaoke can be a great way to get everyone singing and dancing. It’s a great way to break the ice and get everyone involved. 6. Have a dance-off: A dance-off can be a great way to get everyone moving and grooving. It’s a great way to showcase your dance moves and have some fun. 7. Have a potluck: A potluck can be a great way to get everyone involved in the party planning. Everyone can bring their favorite dish to share with everyone else. 8. Have a piñata: A piñata can be a great way to add some excitement to the party. It’s a great way to get everyone involved and have some fun. 9. Have a movie night: A movie night can be a great way to wind down after a long day. It’s a great way to relax and enjoy some good movies with friends and family. 10. Have a bonfire: A bonfire can be a great way to enjoy the outdoors and roast marshmallows. It’s a great way to relax and enjoy some good company. 11. Have a scavenger hunt: A scavenger hunt can be a great way to get everyone involved and have some fun. It’s a great way to explore the area and find hidden treasures. 12. Have a talent show: A talent show can be a great way to showcase everyone’s talents. It’s a great way to have some fun and see what everyone is capable of. 13. Have a DIY station: A DIY station can be a great way to get creative and make something fun. It’s a great way to get everyone involved and have some fun. 14. Have a game night: A game night can be a great way to get everyone involved and have some fun. It’s a great way to play some classic board games or try out some new ones. 15. Have a costume party: A costume party can be a great way to get everyone involved and have some fun. It’s a great way to dress up and be someone else for a night. 16. Have a cocktail-making contest: A cocktail-making contest can be a great way to get everyone involved and have some fun. It’s a great way to showcase your mixology skills and have some fun. 17. Have a dessert-making contest: A dessert-making contest can be a great way to get everyone involved and have some fun. It’s a great way to showcase your baking skills and have some fun. 18. Have a paint night: A paint night can be a great way to get creative and have some fun. It’s a great way to paint something fun and enjoy some good company. 19. Have a board game tournament: A board game tournament can be a great way to get everyone involved and have some fun. It’s a great way to play some classic board games or try out some new ones. 20. Have a DIY cocktail station: A DIY cocktail station can be a great way to get creative and make something fun. It’s a great way to get everyone involved and have some fun. In conclusion, there are so many great experiences that can make any party an unforgettable one. Whether it’s playing games, having a karaoke session, or having a costume party, there are so many ways to have fun and create great memories with friends and family.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值