General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
176645429 Practice:
sahil45
1709B - 11 PyPy 3-64 Accepted 1107 ms 15404 KB 2022-10-17 09:42:44 2022-10-17 09:42:44
→ Source
n,m=map(int,input().split())
l=list(map(int,input().split()))
f=[0]*n
b=[0]*n
for j in range(1,n):
    f[j]=f[j-1]+max(0,l[j-1]-l[j])
    b[-j-1]=b[-j]+max(0,l[-j]-l[-j-1])
for j in range(m):
    s,t=map(int,input().split())
    if s<t:
        print(f[t-1]-f[s-1])
    else:
        print(b[t-1]-b[s-1])        
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details