Unable to determine the error in Python code
Unable to determine the error in Python code
I am trying to solve a problem on codechef using Python 3.
Following is the code written by me.
#import heapq as h
#try with heapq
from sys import stdin, stdout
t = int(stdin.readline())
for i in range(t):
(n, m) = (int(x) for x in stdin.readline().split())
zmbs = [int(x) for x in stdin.readline().split()]
lrk =
for j in range(m):
l, r, k = map(int, stdin.readline().split())
lrk.append([l, r, k])
u =
ans = 0
failed = False
for zi in range(len(zmbs)):
u += [x for x in lrk if x[0] == zi+1]
u.sort(key=lambda x: x[1])
z = zmbs[zi]
while(z > 0):
if u == or u[-1][1] < zi+1:
failed = True
# z cant be killed, exit loop
break
l, r, k = u[-1]
if k > z:
ans += z
u[-1][-1] -= z
zmbs[zi:r] = [x-z for x in zmbs[zi:r]]
z = 0
else:
ans += k
z -= k
zmbs[zi:r] = [x-k for x in zmbs[zi:r]]
u.pop()
if failed: break
if failed: stdout.write('NO')
else: stdout.write('YES ' + str(ans))
However it is showing the result as wrong answer. I am unable to figure out any scenario that I have missed and need help in figuring it out as all test cases are not available on the site.
PS: I don't know C/C++.
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Please copy the problem description into your question rather than have us go follow a link to understand what you're trying to solve
– cricket_007
2 mins ago