After meticulous testing, I know I have the correct solution, but the judge system always returns a NZEC runtime error. There is literally no place for the error to occur!! Why is this?
Here is my code:
def farida(num, arr):
"""
if num == 1: return arr[0]
memo = [None] * (num)
memo[0] = arr[0]
memo[1] = max(arr[0], arr[1])
for i in range(2, len(memo)): # -----|
memo[i] = max( arr[i], memo[i-2] , arr[i] + memo[i-2] ) # |------- O(N)
if memo[i-1] > memo[i]: memo[i] = memo[i-1] # -----|
return memo[-1]
if __ name __ == ‘__ main __’:
# input test cases
ret = ""
test_cases = int( input().strip() )
if test_cases > 0:
for i in range(test_cases):
num = int( input().strip() )
if num > 0:
arr = list( map(int, input().split(’ ')) )
result = str( farida(num, arr) )
else:
input()
result = str(0)
ret += "Case " + str(i+1) + ": " + result + "\n"
print(ret.strip())
created
last reply
- 8
replies
- 949
views
- 2
users
- 2
links