Practice on Toph

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

Shamsu Vai Angrybird

By sayedalmahdi · Limits 1s, 512 MB

Great coder SHAMSU VAI lives at a hostel in Zindabazar area and you know there is a huge crisis of water in that area. He has been living there for N consecutive days. The supply of water to his room comes from the City Corporation tank and he stores water in a container which cannot contain more water than D liter. Everyday A liter of water comes to his room and he needs B liter of water for his use. Sometimes the water supply satisfies him if he can use B liter of water, sometimes not. Initially the container was empty and he never use more water than his satisfaction level. If some water remains after his use then the water is remained stored on the container for the next day. One day his father visited his room and SHAMSU VAI told his father about the problem. Then his father asked Q queries to him regarding the problem. Queries are like this: his father told him an integer X. He had to tell his father about the condition of water on Xth day. You know SHAMSU VAI is very busy with his android project now and so, as the best junior programmer of Leading University you have to help him.


SHAMSU VAI will give you the record of N days. So, the first line of the input will be three integer N,Q,D (1<=N,Q<=100000; 1<=D<=1000000000). The next N lines of input will be two integer Ai,Bi(0<=Ai,Bi<=D) Ai the quantity of water comes to his room and Bi is the quantity of water needed for his satisfaction for the ith day.

Next Q lines of input will be one integer X(1<=X<=N).


For each X you have to print the condition of water in one line like below:


where R is the quantity (in liter) of stored water on the container after water is supplied on that day and string S is "SHAMSU VAI Zindabad" if stored water can satisfy him or "SHAMSU VAI Angrybird" if he is not satisfied.


3 3 20
15 10
12 15
10 15
15 SHAMSU VAI Zindabad
17 SHAMSU VAI Zindabad
12 SHAMSU VAI Angrybird
3 2 30
20 10
12 15
15 15
22 SHAMSU VAI Zindabad
22 SHAMSU VAI Zindabad

Explanation of 1st Sample Case: On the first day he stored 15 liter water and he used his expected 10 liter water. The next day the stored water was (15-10)=5 liter and another 12 liter came. So, he had 12+5= 17 liter stored and used his expected 15 liter. On the third day the stored water was (17-15)=2 liter and another 10 liter came. So, he had 10+2=12 liter stored and used only 12 liter which was below his satisfaction level.



80% Solution Ratio

BruteforcekidEarliest, Jul '17

Tahmid690Fastest, 0.0s

RedwanuzzamanLightest, 3.7 MB

Tahmid690Shortest, 424B


Login to submit

Toph uses cookies. By continuing you agree to our Cookie Policy.