General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
165258236 Virtual:
YERGALI#
1709B - 10 PyPy 3-64 Accepted 1092 ms 15384 KB 2022-07-22 06:22:35 2022-07-22 13:49:08
→ Source
n,m = map(int,input().split())
a = list(map(int,input().split()))
b = [0]*n
c = [0]*n
 
for i in range(1,n):
    b[i] = b[i-1]+max(0,a[i-1]-a[i])
    c[i] = c[i-1]+max(0,-(a[-i-1]-a[-i]))
 
for i in range(m):
    x,y = map(int,input().split())
    if x<=y:
        print(b[y-1]-b[x-1])
    else:
        print(c[-y]-c[-x])
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details