I wrote my code and it works perfectly well when running it, but it shows a problem when i submitted the Question. Please help me re write my code
t=int(input())
for i in range(t):
n,x,y=map(int,input().split())
a= y//3
l= (x-a)//2
f= l+a
if l>=0:
if f>=n:
print("Yes")
else:
print("No")
else:
print("No")
Problem Link: Decorating Christmas Tree Practice Coding Problem - CodeChef
I wonder if this is actually an 1100 problemā¦ ANYWAY!!
Your issue is that you are not optimizing your sources (large ornaments: x)
Since X is your source that is most likely to dispose, try to use your Y first.
Each 3 Y need 1 X, so:
one = min(X, Y//3)
After emptied your option one possibilities, emptie your second (considering the one you already used)
two = (X-one)//2
Finally, this:
# cook your dish here
#from collections import deque,Counter
#from math import ceil, floor
def innum():
return int(input())
def inmany():
return map(int,input().split())
for T in range(innum()):
N,X,Y = inmany()
one = min(X,(Y//3))
two = (X-one)//2
if one+two >= N:
print("YES")
else:
print("NO")
1 Like
But arnt both the codes same? I mean i do agree that your code is better structured, but i dont understand where i went wrong with my approach in this question(My logicā¦)
Nope, we are not using the same logic
I am using an min() function, your question should be asking me why I did that.
When I do this:
one = min(X,Y//3)
Means: āI will reduce Y, but I if donāt have enough X to make an option one ākind one ornamentā then option one is 0ā.
Your code does not do that.
You code directly assumes there will be enough X to make Y//3.
1 Like
Ahh i understand now, thanks a lot!!!
Iām glad
If any wonders are left, let me know.