Python code for 1420C

Правка en1, от codejunk, 2020-10-08 08:09:25

Below mentioned code gives error and i have not seen a single python code successful submission .

1420C2

for i in range(int(input())): n,q=map(int,input().split()) a=list(map(int,input().split())) a=[-1]+a[0:n]+[-1] amin=[] amax=[] k=0 for i in range(1,n+1): if a[i-1]>a[i] and a[i]<a[i+1]: amin.append(a[i]) k-=a[i] elif a[i-1]<a[i] and a[i]>a[i+1]: amax.append(a[i])
k+=a[i] print(k) for j in range(q): l,r=map(int,input().split()) a[l],a[r]=a[r],a[l] d= sorted([l-1,l,l+1,r-1,r,r+1]) for i in set(d): if i>0 and i<n+1:
if a[i] in amax : if a[i-1]>a[i] and a[i]<a[i+1]: amin.append(a[i]) k-=a[i] amax.pop(i) k-=a[i] elif a[i-1]<a[i] and a[i]>a[i+1]: continue else: amax.pop(i) k-=a[i] elif a[i] in amin: if a[i-1]>a[i] and a[i]<a[i+1]: continue elif a[i-1]<a[i] and a[i]>a[i+1]: amax.append(a[i])
k+=a[i] amin.pop(i) k+=a[i] else:
amin.pop(i) k+=a[i] else: if a[i-1]>a[i] and a[i]<a[i+1]: amin.append(a[i]) k-=a[i] elif a[i-1]<a[i] and a[i]>a[i+1]: amax.append(a[i])
k+=a[i]
print(k)

Теги *2100, #dp, #implementation

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский codejunk 2020-10-08 08:10:29 12 Tiny change: 'successful submission .\n#1420C' -> 'successfully submitted .\n#1420C'
en1 Английский codejunk 2020-10-08 08:09:25 1948 Initial revision (published)