CCC '10 J2 - Up and Down

View as PDF

Submit solution

Points: 5
Time limit: 2.0s
Memory limit: 256M

Problem type
Canadian Computing Competition: 2010 Stage 1, Junior #2

Nikky and Byron are playing a silly game in gym class.

Nikky is told by his teacher to walk forward a steps (1 \le a \le 100) and then walk backward b steps (1 \le b \le 100), after which he repeats a forward, b backward, etc. Likewise, Byron is told to walk forward c steps (1 \le c \le 100) and then walk backward d steps (1 \le d \le 100), after which he repeats c forward, d backward, etc. You may assume that a \ge b and c \ge d.

Byron and Nikky have the same length of step, and they are required to take their steps simultaneously (that is, Nikky and Byron will both step forward on their first steps at the same time, and this will continue for each step).

Nikky and Byron start walking from one end of a soccer field. After s steps (1 \le s \le 10\,000), the gym teacher will blow the whistle. Your task is to figure out who has moved the farthest away from the starting position when the whistle is blown.

Input Specification

The input will be the 5 integers a, b, c, d, and s, each on a separate line.

Output Specification

The output of your program will be one of three possibilities: Nikky if Nikky is farther ahead after s steps are taken; Byron if Byron is farther ahead after s steps are taken; Tied if Byron and Nikky are at the same distance from their starting position after s steps are taken.

Sample Input

4
2
5
3
12

Output for Sample Input

Byron

Explanation of Output for Sample Input

Notice that after 12 steps, Nikky has moved 4-2+4-2 steps, for a total of 4 steps from the starting position, whereas Byron has moved 5-3+4 steps, for a total of 6 steps from the starting position. Thus, Byron is ahead.


Comments


  • -1
    jasonstorybank  commented on April 20, 2024, 2:28 p.m.

    when the teacher makes nicky and byron walk 10,000 steps output:I quit


  • -8
    960t  commented on Oct. 21, 2022, 8:18 p.m.

    This comment is hidden due to too much negative feedback. Show it anyway.


    • -7
      xiaolong  commented on Nov. 30, 2022, 11:59 p.m.

      This comment is hidden due to too much negative feedback. Show it anyway.


    • -15
      CoderGrinder  commented on Nov. 24, 2022, 11:15 p.m.

      This comment is hidden due to too much negative feedback. Show it anyway.


  • 1
    ASKmenot  commented on Oct. 16, 2022, 4:57 p.m.

    Why is my code exceeding the time limit? I know it's probably related to my two while loops, but I don't see why it would do that.


    • 1
      ethan202107  commented on Nov. 25, 2022, 1:23 a.m.

      You could try making a function to find the numbers too. It will make your life much easier


    • 1
      panzer_shrek  commented on Oct. 16, 2022, 8:34 p.m.

      You don't have to iterate so many times, and your calculation method will result in WA even if the time limit will allow your answer. Think about this problem a lot more carefully and read the explanations for the sample outputs.


  • 0
    QiQi  commented on Nov. 5, 2021, 12:39 a.m. edited

    In the case where Byron or Nikky do not have enough time for the amount of steps, just add or subtract the remaining time depending if he or she is going forward or backward.


  • 1
    sdesai9192  commented on July 20, 2021, 6:55 p.m.

    Why doesn't my test case #4 work?


    • 15
      Badmode  commented on July 20, 2021, 9:07 p.m. edit 2

      Try this testcase (also for others failing testcase #4):

      10
      0
      20
      0
      5

      After s steps, the gym teacher will blow the whistle.

      Both Nikky and Byron traveled 5 steps, so the correct output should be Tied, not Byron.


      • 1
        Random_User1111  commented on Sept. 25, 2022, 7:46 p.m. edit 2

        I Used your input and got tied as my output, however I still got WA when I submit my solution. But still thanks for the tip!


      • 1
        emanresu  commented on Feb. 20, 2022, 10:33 p.m.

        if i input 10 0 20 0 5

        i do output tied but i still fail testcase 4


      • 1
        sdesai9192  commented on July 21, 2021, 11:28 a.m.

        Oh, I think I know what I was doing wrong- thanks!


  • 40
    institutionalisation  commented on July 23, 2018, 12:10 p.m.

    Spent half an hour spelling Byron as Bryon and Nikky as Nicky.


  • -26
    loltrollkill  commented on Feb. 7, 2018, 11:24 p.m.

    This comment is hidden due to too much negative feedback. Show it anyway.


    • 4
      KevinLu  commented on Feb. 16, 2018, 11:36 p.m.

      Tied if Byron and Nikky are at the same distance from their starting position after s steps are taken.


      • 0
        DotonPY  commented on Oct. 10, 2020, 12:44 a.m.

        That means it outputs 'Tied'.


  • -79
    Yuting9  commented on April 15, 2015, 1:14 p.m.

    This comment is hidden due to too much negative feedback. Show it anyway.


    • 13
      quantum  commented on April 15, 2015, 1:19 p.m.

      How do you know what the test case should be? Think first whether it would be arrogant to suggest all the people who got AC are wrong.


      • 108
        Yuting9  commented on April 17, 2015, 2:42 p.m.

        I had read the question statement wrong. I apologize for my previous comment.