复习差分
刚刚复习了一下差分,发现写的并不熟练,出现很多问题
n,m=[int(num) for num in input().split()]
nums=[int(num) for num in input().split()]
dp=[0 for i in range(n)]
dp[0]=nums[0]
for i in range(1,n):
dp[i]=nums[i]-nums[i-1]
dp.append(0)#在数组最后面添加0,防止dp[-1]越界
for i in range(m):
temp=[int(num) for num in input().split()]
dp[temp[0]-1]+=temp[2]
dp[temp[1]]-=temp[2]
res=0
for i in range(n):
res+=dp[i]
print(res,end=' ')