Codeforces Round #426 (Div. 2), problem: (B) The Festive Evening Solution In C/C++

#include<cstdio>

bool pd[26];
char s[1000007];
int n,k,size,last[26];

int main(){
scanf(“%d%d%s”,&n,&k,&s);
for (int i=0;i<n;++i) last[s[i]-‘A’]=i;
for (int i=0;i<n;++i){
if (!pd[s[i]-‘A’]) pd[s[i]-‘A’]=true,++size;
if (size>k){
printf(“YES”);
return 0;
}
if (i==last[s[i]-‘A’]) –size;
}
printf(“NO”);
}

#include<cstdio>

bool pd[26];
char s[1000007];
int n,k,size,last[26];

int main(){
scanf(“%d%d%s”,&n,&k,&s);
for (int i=0;i<n;++i) last[s[i]-‘A’]=i;
for (int i=0;i<n;++i){
if (!pd[s[i]-‘A’]) pd[s[i]-‘A’]=true,++size;
if (size>k){
printf(“YES”);
return 0;
}
if (i==last[s[i]-‘A’]) –size;
}
printf(“NO”);
}

More from author

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Related posts

Advertismentspot_img

Latest posts

Stop Buying Cheap Alternatives This Viral Kitchen Gadgets Is the Real Deal

📢 As an Amazon Associate, I earn from qualifying purchases.After putting the Viral Kitchen Gadgets through a proper 30-day real-world test, I can tell...

Extra support arrives as Ohakune in race to restore water supply

Efforts to restore the main municipal water network in Ohakune have escalated significantly as specialist repair crews from across New Zealand arrive to assist...

7 Reasons This Dog Car Seat Cover Is Worth Every Single Penny

📢 As an Amazon Associate, I earn from qualifying purchases.After putting the Dog Car Seat Cover through a proper 30-day real-world test, I can...

Want to stay up to date with the latest news?

We would love to hear from you! Please fill in your details and we will stay in touch. It's that simple!