General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
167138462 Practice:
newgate
1709B - 11 PyPy 3 Accepted 1637 ms 17052 KB 2022-08-05 20:33:40 2022-08-05 20:33:40
→ Source
n,m=map(int,input().split())
c=[int(i) for i in input().split()]
f=[0]*n
g=[0]*n
for i in range(1,n):
	f[i]=f[i-1]+max(0,c[i-1]-c[i])
	g[-i-1]=g[-i]+max(0,c[-i]-c[-i-1])
for i in range(m):
	x,y=map(int,input().split())
	if x<y:
		print(f[y-1]-f[x-1])
	else:
		print(g[y-1]-g[x-1])
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details