Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Save Abul Bhai!

By Minhaj_10 · Limits 1s, 512 MB

In a parallel universe North African nation of the Republic of Wadiya has been ruled by Admiral-General Haffaz Aladeen. The Dictator Aladeen build a video game called ‘Dead-land’. Aladeen forces one of his employee named ‘Abul Bhai’ to become first experimental user of the game.

In this game if ‘Abul Bhai’ win $P$ number of matches consecutively Aladeen will punish him for hacking the game and if ‘Abul Bhai’ lose $Q$ number of matches consecutively again he will be punished by Aladeen for being a loser. If ‘Abul Bhai’ is able to skip both cases he is safe.

Determine whether ‘Abul Bhai’ is safe or not.


The first line of input contains three integers $N \hspace{.1cm} (1 \leq N \leq 2×10^5 )$, $P \hspace{.1cm} (1 \leq P \leq 10^5)$ & $Q \hspace{.1cm} (1 \leq Q \leq 10^5)$.
$N$ represents the number of matches Abul Bhai played.

The second line of input contains a string $S$ consisting of $N$ characters where each character contains ‘$0$’ or ‘$1$’. Here, ‘$0$’ represents that he lost the match and ‘$1$’ represents he won the match.


If he is safe print “Abul Bhai is safe” else print “Abul Bhai is in danger”.


10 5 3                                                 
Abul Bhai is safe



    91% Solution Ratio

    aritra741Earliest, 2w ago

    aritra741Fastest, 0.0s

    EgorKulikovLightest, 0 B

    aosafzawad_CShortest, 163B


    Login to submit


    Here you have to count the maximum number of consecutive zero and one. Suppose a is the maximum cons...