KARATEKID2 - Editorial

PROBLEM LINK:

Practice
Contest

Author: Riddhish Lichade
Tester: Prathamesh Sogale
Editorialist: Ram Agrawal

DIFFICULTY:

SIMPLE

PREREQUISITES:

Math

PROBLEM:

Dre is a karate student. He is preparing for a karate tournament which will take place in N days. Currently, his strength is S1. To win the competition, he needs a minimum strength of S2.

Each day of practice helps Dre gain strength by S3. While each day of rest decreases his strength by S4. He cannot practice continuously for more than 5 days, i.e. after 5 days of continuous practice, he needs to rest at least for 1 day.

Dre is too busy in practice so he has asked you for help. Your task is to help Dre find the minimum number of days he should practice to win the competition as he also needs some rest if possible before the tournament.

Note: S3 can be negative in case Dre is practicing in the wrong way.

EXPLANATION:

At first find Dre’s final strength if he does not practice for any day that is he rests for all days. Then compare it with the minimum strength he needs to win the competition. Also, take care that he will not practice continuously. He needs rest after every five days. In the end don’t forget to take care of the base cases.

SOLUTIONS:

Setter's Solution
from sys import stdin
for _ in range(int(stdin.readline())):
    n, s1, s2, s3, s4=map(int, stdin.readline().strip().split())
    x = s1-(s4*n)
    rest=n//6
    work=n-rest
    y = s1+(s3*work)-(s4*rest)
    if(x>=s2):
        print(0)
        continue
    if(y<s2):
        print("FAIL")
        continue
    if(s3<=s4):
        print("FAIL")
        continue
    days=0
    for i in range(1,n+1):
        if(i%6!=0):
            x+=s4+s3
            days+=1
        if(x>=s2):
            print(days)
            break
    else:
        print("FAIL")