I am getting repeated NZEC errors while using Python

This solution is for problem code: PIPSQUIK in the beginner section of practice and learn.
I wrote a code which I considered was the most efficient and kept getting NZEC errors, while another code which ran through more iterations than mine got the right answer. Am i missing something in python?

My code:

for _ in range(int(input())):
n,h,y1,y2,l=map(int,input().split())
for z in range(n):
a,b=map(int,input().split())
if a==1:
if(h-y1>b):
l-=1
else:
if(y2<b):
l-=1
if(l<1):
print(z)
break
else:
print(n)

Code that got passed:

cook your dish here

for _ in range(int(input())):
n, h, y1, y2, l = map(int, input().split())

ans = 0
for _ in range(n):
    t, x = map(int, input().split())
    
    if t == 1:
        if h-y1 > x: l -= 1
    else:
        if y2 < x: l -= 1
    
    if l > 0:
        ans += 1

print(ans)

Even though my code runs for lesser iterations, i got an NZEC error. It is also to be noticed that when the person whose code got passed, usage of the break statement is causing an NZEC error and not using it leads to a right answer. SHould i learn something before continuing.

Please either format your code or (better!) link to your submission - the forum software has mangled it and it won’t compile! :slight_smile:

https://www.codechef.com/viewsolution/53411001
This is the link to my submission. Thanks for helping me out btw :smiley:

1 Like

Thanks! I’ve only briefly glanced at the problem; I hope this is a valid test input:

2
5 2 1 1 1
2 10
2 10
2 10
2 10
2 10
5 2 1 1 1
2 10
2 10
2 10
2 10
2 10

Yepp, that is a valid test input

1 Like

Cool - it crashes your solution.

I’m sorry if this is a silly thing to ask. But may I know why the code crashes? And do you have tips to crack down corner cases like you.

I’m going to leave that for you to figure out - get debugging!

in this case, I just spotted the logical flaw and crafted a testcase to expose it :man_shrugging:

Friends, i have got the reason for the nzec error.
The reason is that the ide is not able to read our input.

The main cause of this error is that we forget to give our input in custom input section and without giving input we run our code and that is why we get error.

So to get rid of nzec error, what we should do is to copy the input from the question and paste it in the custom input section and then run the code.
this will surely help.

even after doing this you get nzec error then surely there is error in your code and try your code in some other ide to identify the error.

Thanks,
Raj

Lol alrightt thanks for helping

1 Like

Thank you for the suggestion :smiley:

Thank you so much! I found out where I went wrong thanks to your testcase!

2 Likes