I am getting error please help Problem code = Cops

link of my submission is CodeChef: Practical coding for everyone
here is my code

for _ in range(int(input())):

M,x,y = map(int, input().split())

lis = list(map(int, input().split()))

low = []

up =[]

e = 0

coprange = x * y

for item in lis:

    low.append(item - coprange)

    up.append(item + coprange)

    

for i in range(len(low)):

    if low[i] < 0:

        low[i] = 1

                

for i in range(len(up)):

    if up[i]>100:

        up[i] = 100

        

low1 =sorted(low)

up1 =sorted(up)

for i in range(1,len(low)):

    c = low1[i] - up1[i-1]

    if c>0:

        e += c



if up1[i]<100:

   e += (100 - up1[-1])

    
print(e)

There are three extra print statements in your submitted code while there’s only one print Statement in this code, maybe check if that’s causing the problem.

yes there are extra print statements which I had put for debugging purpose but after removing them still I am not getting correct output

the range covered by cop i is {low[i],up[i]} you should sort that pair, if you sort low and up independently you loose the information of the pair

are you getting NZEC?
put your code in try except like this
try:
your code
except:
pass

2 10 2
21 75

for this tc the ans should be 19 not 18

reason:

for 21 : max reach is from 1 to 41
for 75 : max reach is from 55 to 95
so the nos which are left unreached are 41 to 55 i.e 14 and 95 to 100 i.e 5 and 14+5=19 != 18

bro just look at the problem in example same data set is used and there is also same answer 18
even explanation is given below how 18 will be output for that input

no i am not getting nzec, I am getting wrong answer during submission but when I run a test I get correct output

Your solution gives the wrong output for the following test input:

1
3 4 3
28 32 73
1 Like

I don’t think so, since i am generating low and high by subtracting and adding same value to all M
so they will always be in pair

okay can you please tell what changes should i make to make it work as it is expected

You’ve got a 100% reproducible testcase now; figure out the mistake that is causing your solution to give the wrong answer, and then work out how to correct it :slight_smile:

2 Likes

Most of the people who post a doubt expect a magical wizard to pop up and correct their code, so that they can finally see that green tick over that problem. They don’t understand it’s more important to realize the mistake that they made. I like how you provide counter test cases and push people to correct their own code!

2 Likes

Thanks - I always feel kind of like a Dick when I do it, but I guess you have to be cruel to be kind :slight_smile:

3 Likes