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
    IDKEthan  commented on Sept. 21, 2024, 1:10 a.m. edit 5

    can someone help? my code is this

    a = int(input())
    
    b = int(input())
    
    c = int(input())
    
    d = int(input())
    
    s = int(input())
    
    stuff = a - b
    
    stuff2 = c - d
    
    morestuff = stuff
    
    morestuff2 = stuff2
    
    for i in range(1):
    
        if morestuff < s:
            morestuff += stuff
        elif morestuff == s and morestuff > stuff2:
            print("Byron")
        elif morestuff2 < s:
            morestuff2 += stuff2
        elif morestuff2 == s and stuff2 > stuff:
            print("Nikky")
    

    • 1
      bowen_wu  commented on Oct. 24, 2024, 11:06 p.m. edited
      1. why is it for i in range(1): you should use a while True loop and break it after
      2. you inversed Byron and Nikky
      3. use 2 while loops: 1 for calculating Nikky, another for calculating Byron and then use a if elif else to print
      4. you forgot about the output Tied
      5. you need add c and to substract d because the input 1(sample input) has 5 and 3 and you need to add c(5), substract d(3), then add 4(c but you can only move 4 of the 5 steps because of s)
      6. Post your submission(link) to only let the people who got 100 percent at the question to see the submission to not let others copy paste