我的代码有什么问题?它只通过了我的 6 个测试用例,我确信我犯了一些错误,但我无法弄清楚。此外,如果有人能帮助我理解这段代码的空间和时间复杂性,我将不胜感激。谢谢你。
def arrayManipulation(n, queries):
arr = [0]*(n+2)
for q in queries:
print(q)
a = q[0]
b = q[1]
k = q[-1]
arr[a] += k
arr[b+1] -= k
print(arr)
max_sum = temp = 0
for i in arr:
print(i)
temp += i
print("TEMP:",temp)
max_sum = max(max_sum,temp)
print("MAXSUM:",max_sum)
return max_sum
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
nm = input().split()
n = int(nm[0])
m = int(nm[1])
queries = []
for _ in range(m):
queries.append(list(map(int, input().rstrip().split())))
result = arrayManipulation(n, queries)
fptr.write(str(result) + '\n')
fptr.close()