Subsequences of Length Two SOLUTIONS Codeforces Round #667 (Div. 3)

Subsequences of Length Two SOLUTION

You are given two strings s and t comprising of lowercase Latin letters. The length of t is 2 (for example this string comprises just of two characters). 

In one move, you can pick any character of s and supplant it with any lowercase Latin letter. All the more officially, you pick some I and supplant si (the character at the position I) with some character from ‘a’ to ‘z’. 

You need to do close to k substitutions so that expands the quantity of events of t in s as an aftereffect. 

Review that an aftereffect is a succession that can be gotten from the given grouping by erasing at least zero components without changing the request for the rest of the components. 

 

Information 

The principal line of the information contains two numbers n and k (2≤n≤200; 0≤k≤n) — the length of s and the most extreme number of moves you can make. The second line of the information contains the string s comprising of n lowercase Latin letters. The third line of the information contains the string t comprising of two lowercase Latin letters. 

 

Yield 

Print one number — the most extreme conceivable number of events of t in s as an aftereffect on the off chance that you supplant close to k characters in s ideally. 

 

Models 

inputCopy 

4 2 

bbaa 

abdominal muscle 

 

outputCopy 

 

inputCopy 

7 3 

asddsaf 

sd 

 

outputCopy 

10 

inputCopy 

15 6 

qwertyhgfdsazxc 

qa 

 

outputCopy 

16 

 

inputCopy 

7 2 

abacaba 

aa

 

outputCopy 

15 

 

Note 

In the principal model, you can acquire the string “abab” supplanting s1 with ‘an’ and s4 with ‘b’. At that point the appropriate response is 3. 

In the subsequent model, you can get the string “ssddsdd” and find the solution 10. 

In the fourth model, you can get the string “aaacaaa” and find the solution 15.

DOWNLOAD THE SOLUTIONS

2 thoughts on “Subsequences of Length Two SOLUTIONS Codeforces Round #667 (Div. 3)”

Leave a Comment