ECOO '18 R1 P1 - Willow's Wild Ride

View as PDF

Submit solution

Points: 5 (partial)
Time limit: 30.0s
Memory limit: 64M

Problem type

Mandy is a working artist and is commissioned to create some art pieces for 2018. The client wants Mandy to create art pieces out of cardboard boxes to display at the local art show. Occasionally, Mandy plans to drive by the local store on her way home to grab some boxes for her art pieces.

Mandy's cat, Willow, likes to play with every box that Mandy brings home. Willow plays with a box for T days before getting bored of it. Once Willow is bored with a box, she never returns to it again, meaning that Mandy can finally use the empty box in her art projects.

If Mandy brings home another box before Willow finishes playing with the previous one, Willow will wait until she is bored with the previous box before moving onto the new one.

Given Mandy's box-shopping habits over the next N days, can you determine by how many days the project will be delayed due to Willow?

Input Specification

The standard input will contain 10 datasets.

Each dataset begins with two integers T (2 \le T \le 7) and N (1 \le N \le 365). The next N lines each contain either the letter E or B which represent whether Mandy came home empty-handed or with a box that day.

Output Specification

For each dataset, output the number of days that Willow will be playing with the boxes after the N days given in the dataset.

Sample Input

3 5
2 4

Sample Output


Educational Computing Organization of Ontario - statements, test data and other materials can be found at


  • -1
    mcs618  commented on July 17, 2022, 8:56 a.m.

    "There is a trick:if the cat has played all the previous boxes,the expected deadline should minus 1"

    Not sure what you mean by that, but there are no negative days. I fully solved the problem and one of my earlier errors that I found and fixed was that I was computing (potentially) negative days past the N given days. You can't have that.

  • 0
    mikoSingle  commented on May 27, 2022, 9:19 p.m.

    came back after 2 weeks and got it now....last two test cases have a point in the middle of the data set where Willow finishes playing with the current boxes before getting more boxes.

  • 0
    mikoSingle  commented on May 11, 2022, 12:10 p.m.

    I'm also having trouble with the last dataset of the 2nd and 3rd test case. Something must be wrong with my math, but I don't know what the last dataset is testing? Can anyone help?

  • 0
    benjahb  commented on July 25, 2021, 12:34 p.m. edit 3

    what is different in the last test case? I keep failing on it.

    Edit: Nvm I figured it out with some help

    • 0
      XIANZHANLONG  commented on Sept. 20, 2021, 1:47 a.m.

      There is a trick:if the cat has played all the previous boxes,the expected deadline should minus 1