I am getting runtime error(Extra memory usage) in codechef. I am getting the correct expected output whenever i use Other IDE to run my python code.
Question is: Chefland has 7 days in a week. Chef is very conscious about his work done during the week.
There are two ways he can spend his energy during the week. The first way is to do x units of work every day and the second way is to do y (>x) units of work for the first d (<7) days and to do z (<x) units of work thereafter since he will get tired of working more in the initial few days.
Find the maximum amount of work he can do during the week if he is free to choose either of the two strategies.
My code:
# cook your dish here
t = int(input("Number of test cases"))
print(t)
i= 0
while i <= t:
i += 1
if i > t:
break
d = int(input("No of Days"))
x = int(input("Number of units of work everyday"))
y = int(input(f"No of units of work for {d} days"))
z= int(input("No of units of work for remaining days"))
a = 7*x
if y > x:
if d < 7:
b = d * y
if z < x:
c = z * (7-d)
sum = b + c
print(max(a,sum))
I do not get any error when I run the code in the online complier using python but when I submit it. It shows that there is runtime error(RE).It means that i have to reduce my memory usage of the code. When I run and execute the memory usage is 17.968kb but it should be below 4.882 kb.
How can I reduce the memory usage of my code.
How can I solve this.
Thank You in Advance.
I have tried to use try and except. To remove the runtime error.
mycode:
#cook your dish here
try:
# TODO: write code...
T = int(input())
print(T)
i= 0
while i <= T:
i += 1
if i > T:
break
d, x, y, z = map(int, input().split())
a = 7*x
if y > x:
if d < 7:
b = d * y
if z < x:
c = z * (7-d)
sum = b + c
print(max(a,sum))
except Exception:
pass
The execution is running perfectly fine as expected output but when i submit the answer it is shown that wrong answer.When i submit it without adding try and except function then "runtime error(NZEC)" is being displayed.