Problem:


Problem A:サイゾウ

  

    ある国で「サイゾウ」というテレビ番組が流行している．
    この番組は参加者がフィールドアスレチックに挑戦し，
    見事攻略すれば賞金をもらえるというものである．
  

  

    フィールドアスレチックは高さが異なるブロックを一列に並べて作られていて，
    攻略のためにはいかにして段差を登り降りするかが重要になる
    （図1）．
    この番組に参加することになったあなたの友人は，
    フィールドアスレチックの構造が与えられたときに，
    登らなければならない最大の段差と降りなければならない最大の段差を
    計算するプログラムを書いてほしいと，
    凄腕プログラマーであるあなたに依頼してきた．
  

  
    

	

	  
	    
	  
	

	

	  図1: アスレチックの構造の例（入力例の最初のデータセット）．
	

    

  
Input

  

    入力の1行目にはデータセットの個数 t
    (0 < t ≤ 100) が与えられる．
    この行に引き続き t 個のデータセットが与えられる．
  

  

    データセットの1行目はフィールドアスレチックを構成している
    ブロックの個数 n
    (2 ≤ n ≤ 100) である．
    2行目にはスタートからゴールまでのブロックの高さを示す整数が
    順に n 個与えられる．
    1番目がスタート， n番目がゴールに対応している．
    これらの整数は1つの空白文字で区切られている．
    各ブロックの高さ h は 0 < h ≤ 1000 を満たす．
  

  
Output

  

    各データセットに対し，
    登らなければならない最大の段差の大きさと，
    降りなければならない最大の段差の大きさを，
    1つの空白文字で区切って1行に出力せよ．
    なお，登る段差がない，または降りる段差がない場合は，
    対応する最大の段差の大きさは 0 とすること．
  

  
Sample Input

  

5
5
10 70 30 50 90
2
20 100
2
100 30
3
50 50 50
7
123 45 678 901 234 567 890

  
Output for the Sample Input

  

60 40
80 0
0 70
0 0
633 667



Sample input:
5
5
10 70 30 50 90
2
20 100
2
100 30
3
50 50 50
7
123 45 678 901 234 567 890


Sample output:
60 40
80 0
0 70
0 0
633 667

Submission status: Wrong Answer

Solution code:
#coding:UTF-8                                                                                                                                                                                                     
                                                                                                                                                                                                                  
def Calculate(rows) :                                                                                                                                                                                             
    up, down = 0, 0                                                                                                                                                                                               
                                                                                                                                                                                                                  
    for x in range(0, len(rows) - 1) :                                                                                                                                                                            
        tmp = rows[x + 1] - rows[x]                                                                                                                                                                               
                                                                                                                                                                                                                  
        if tmp < 0 :                                                                                                                                                                                              
            tmp = abs(tmp)                                                                                                                                                                                        
                                                                                                                                                                                                                  
            if down < tmp :                                                                                                                                                                                       
                down = tmp                                                                                                                                                                                        
                                                                                                                                                                                                                  
        elif tmp > 0 :                                                                                                                                                                                            
            if up < tmp :                                                                                                                                                                                         
                up = tmp                                                                                                                                                                                          
                                                                                                                                                                                                                  
        else :                                                                                                                                                                                                    
            pass                                                                                                                                                                                                  
                                                                                                                                                                                                                  
    print("{0} {1}".format(up, down))                                                                                                                                                                             
                                                                                                                                                                                                                  
    return(up, down)                                                                                                                                                                                              
                                                                                                                                                                                                                  
def Main() :                                                                                                                                                                                                      
    fields = int(input())                                                                                                                                                                                         
    up, down = [], []                                                                                                                                                                                             
                                                                                                                                                                                                                  
    for x in range(fields) :                                                                                                                                                                                      
        blocks_q = int(input())                                                                                                                                                                                   

        blocks = input().split(' ')
        blocks = [int(x) for x in blocks]

        if blocks_q != len(blocks) : 
            # error
            pass

        tmp_up, tmp_down = Calculate(blocks)
        up.append(tmp_up)
        down.append(tmp_down)
    
    for x in range(len(up)) : 
        print("{0} {1}".format(up[x], down[x]))


if __name__ == "__main__" : 
    Main()

Submission status: Accepted

Solution code:
t = int(input())
for _ in range(t):
  n = int(input())
  lst = list(map(int, input().split()))
  M = m = 0
  for i in range(n - 1):
    M = max(lst[i + 1] - lst[i], M)
    m = min(lst[i + 1] - lst[i], m)
  print(M, -m)

Submission status: Accepted

Solution code:
d = int(input())
for i in range(d):
    n = int(input())
    l = list(map(int, input().split()))
    dis = [l[i+1] - l[i] for i in range(n - 1)]
    M, m = max(dis), min(dis)
    if M > 0 and m > 0:
        print(M, 0)
    elif M < 0 and m < 0:
        print(0, abs(m))
    else:
        print(M, abs(m))

Submission status: Accepted

Solution code:
all_count = int(raw_input())

for i in range(all_count):
    dansa_count = int(raw_input())
    lis = raw_input().split(' ')
    dansa_lis = [int(num) for num in lis]
    
    up_lis = []
    down_lis = []
    for i in range(dansa_count-1):
        if dansa_lis[i] <= dansa_lis[i+1]:
            up = dansa_lis[i+1] - dansa_lis[i]
            up_lis.append(up)
        else:
            down = dansa_lis[i] - dansa_lis[i+1]
            down_lis.append(down)
    else:
        up_lis.append(0)
        down_lis.append(0)

    up_lis.sort()
    down_lis.sort()
    
    print up_lis[-1], down_lis[-1]

Submission status: Accepted

Solution code:
# solve
def solve(n, block):
    max_up = 0
    max_down = 0
    for i in range(n-1):
        if block[i] < block[i+1]:
            max_up = max(max_up, block[i+1]-block[i])
        elif block[i] > block[i+1]:
            max_down = max(max_down, block[i]-block[i+1])

    return (max_up, max_down)

# main function
if __name__ == '__main__':
    t = int(input())

    for i in range(t):
        n = int(input())
        tmp_block = input().split()

        block = []
        for j in range(n):
            block.append(int(tmp_block[j]))

        max_up, max_down = solve(n, block)
        print(max_up, max_down)

Submission status: Accepted

Solution code:
n = input()

for _ in xrange(n):
	h = input()
	up = 0
	down = 0
	wall = map(int,raw_input().split())
	now = wall[0]
	for var in wall[1:]:
		if var > now and var - now > up:
			up = var - now
		elif var < now and now - var > down:
			down = now - var
		now = var
		
	print up,down

Submission status: Accepted

Solution code:
#coding:UTF-8                                                                                                                                                                                                     
                                                                                                                                                                                                                  
def Calculate(rows) :                                                                                                                                                                                             
    up, down = 0, 0                                                                                                                                                                                               
                                                                                                                                                                                                                  
    for x in range(0, len(rows) - 1) :                                                                                                                                                                            
        tmp = rows[x + 1] - rows[x]                                                                                                                                                                               
                                                                                                                                                                                                                  
        if tmp < 0 :                                                                                                                                                                                              
            tmp = abs(tmp)                                                                                                                                                                                        
                                                                                                                                                                                                                  
            if down < tmp :                                                                                                                                                                                       
                down = tmp                                                                                                                                                                                        
                                                                                                                                                                                                                  
        elif tmp > 0 :                                                                                                                                                                                            
            if up < tmp :                                                                                                                                                                                         
                up = tmp                                                                                                                                                                                          
                                                                                                                                                                                                                  
        else :                                                                                                                                                                                                    
            pass                                                                                                                                                                                                  
                                                                                                                                                                                                                  
    return(up, down)                                                                                                                                                                                              
                                                                                                                                                                                                                  
def Main() :                                                                                                                                                                                                      
    fields = int(input())                                                                                                                                                                                         
    up, down = [], []                                                                                                                                                                                             
                                                                                                                                                                                                                  
    for x in range(fields) :                                                                                                                                                                                      
        blocks_q = int(input())                                                                                                                                                                                   
                                                                                                                                                                                                                  
        blocks = input().split(' ')
        blocks = [int(x) for x in blocks]

        if blocks_q != len(blocks) : 
            # error
            pass

        tmp_up, tmp_down = Calculate(blocks)
        up.append(tmp_up)
        down.append(tmp_down)
    
    for x in range(len(up)) : 
        print("{0} {1}".format(up[x], down[x]))


if __name__ == "__main__" : 
    Main()

Submission status: Accepted

Solution code:
n=int(input())
while n:
    input()
    n-=1
    a=list(map(int,input().split()))
    u,d=0,0
    for i in range(1,len(a)):
        if a[i]-a[i-1]>0:u=max(a[i]-a[i-1],u)
        elif a[i]-a[i-1]<0:d=max(a[i-1]-a[i],d)
    print(u,d)

Submission status: Accepted

Solution code:
for _ in range(int(input())):
    _= int(input())
    upv=dov=0
    h= list(map(int, input().split()))
    for i in range(len(h)-1):
        upv= max(upv, h[i+1]-h[i])
        dov= max(dov, h[i]-h[i+1])
    print(upv, dov)

Submission status: Accepted

Solution code:
t=int(input())
for count in range(t):
    n=int(input())
    h_list=[int(i) for i in input().split(" ")]
    delta_list=[]
    for i in range(n-1):
        delta_list.append(h_list[i+1]-h_list[i])

    if max(delta_list)>0:
        max_up=max(delta_list)
    else:
        max_up=0

    if min(delta_list)<0:
        max_down=min(delta_list)*(-1)
    else:
        max_down=0

    print("%d %d" %(max_up,max_down))

Submission status: Accepted

Solution code:
t = int(input())
for _ in range(t):
    n = int(input())
    h = list(map(int, input().split()))
    maxv = minv = 0
    for i in range(len(h)-1):
        maxv = max(maxv, h[i+1]-h[i])
        minv = max(minv, h[i]-h[i+1])
    print(maxv, minv)

Submission status: Accepted

Solution code:
t = int(input())
for _ in range(t):
    n = int(input())
    blocks = list(map(int, input().split()))
    ans = [0, 0]
    for i in range(1, n):
        ans[0] = max(ans[0], blocks[i] - blocks[i-1])
        ans[1] = max(ans[1], blocks[i-1] - blocks[i])
    print(*ans)

Submission status: Accepted

Solution code:
t = int(input())
for _ in range(t):
    n = int(input())
    blocks = list(map(int, input().split()))
    maxv = minv = 0
    for i in range(1, n):
        maxv = max(maxv, blocks[i] - blocks[i-1])
        minv = max(minv, blocks[i-1] - blocks[i])
    print(maxv, minv)

Submission status: Accepted

Solution code:
for _ in range(int(input())):
    n, a = int(input()), list(map(int, input().split()))
    d = [0, 0]
    for i in range(1, n):d = [max(a[i] - a[i - 1], d[0]), max(a[i - 1] - a[i], d[1])]
    print(*d)

Submission status: Accepted

Solution code:
ans = []
t = input()
s = 0
while s != t:
    n = input()
    step = map(int,raw_input().split())
    upMax = 0
    downMax = 0
    for i in range(n-1):
        if step[i+1] - step[i] > upMax:
            upMax = step[i+1] - step[i]
        if step[i] - step[i+1] > downMax:
            downMax = step[i] - step[i+1]
    temp = str(upMax)+' '+str(downMax)
    ans.append(temp)
    s += 1

for i in ans:
    print i

Submission status: Accepted

Solution code:
t=input()
for j in range(t):
    n=input()
    L=map(int,raw_input().split())
    mi,ma=0,0
    for i in range(len(L)-1):
        if L[i]>L[i+1]:
            mi=min(mi,L[i+1]-L[i])
        else:
            ma=max(ma,L[i+1]-L[i])
    print ma,-mi

Submission status: Accepted

Solution code:
t=input()
for i in range(t):
    up,dw=0,0
    n=input()
    b=map(int,raw_input().split())
    for j in range(n-1):
        if   b[j]<b[j+1]: up=max(up,b[j+1]-b[j])
        elif b[j]>b[j+1]: dw=max(dw,b[j]-b[j+1])
    print up,dw

Submission status: Accepted

Solution code:
import sys

def solve():
    c = int(raw_input())
    for i in range(c):
        n = int(raw_input())
        data = map(int, raw_input().split())
        u,d = 0,0
        for i in range(len(data) - 1):
                if data[i + 1] - data[i] > 0 and data[i + 1] - data[i] > u:
                        u = data[i + 1] - data[i] 
                elif data[i + 1] - data[i] < 0 and data[i] - data[i + 1] > d :
                        d = data[i] - data[i + 1]
        print u,d
if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
for i in range(input()):
	n=input()
	a=map(int,raw_input().split())
	l=[a[i+1]-a[i] for i in range(n-1)]
	print max(0,max(l)),abs(min(0,min(l)))

Submission status: Accepted

Solution code:
for j in [1]*input():
	n=input()
	a=map(int,raw_input().split())
	l=[a[i+1]-a[i] for i in range(n-1)]
	print max(0,max(l)),-min(-0,min(l))

Submission status: Accepted

Solution code:
for t in xrange(input()):
    up = 0; down = 0;
    n = input()
    h = map(int, raw_input().split())
    print max([0]+[h[i+1]-h[i] for i in xrange(n-1)]), max([0]+[h[i]-h[i+1] for i in xrange(n-1)])

Submission status: Accepted

Solution code:
for t in xrange(input()):
    n = input()
    h = map(int, raw_input().split())
    print max(0, max(h[i+1]-h[i] for i in xrange(n-1))), max(0, max(h[i]-h[i+1] for i in xrange(n-1)))

Submission status: Accepted

Solution code:
n = int(input())
for i in range(n) :
    max_up = 0
    max_down = 0
    m = int(input())
    dansa = list(map(int, input().split()))
    for j in range(len(dansa)-1) :
        x = dansa[j+1] - dansa[j]
        if x > max_up :
            max_up = x
        if -x > max_down :
            max_down = -x
    print(max_up, max_down)

Submission status: Accepted

Solution code:
n = int(input())
for j in range(n):
    a = int(input())
    b = list(map(int,input().split()))
    hop = []
    for i in range(a-1):
        hop.append(b[i+1]-b[i])
    hop.sort(reverse = True)
    if hop[0] <= 0:
        print(0,end = " ")
    else:
        print(hop[0],end = " ")
    if hop[-1] >= 0:
        print(0)
    else:
        print(-(hop[-1]))

Submission status: Accepted

Solution code:
n = int(input())
for _ in range(n):
    x = int(input())
    lst = list(map(int, input().split()))
    y, z = 0, 0
    for j in range(1, x):
        y = max(y, lst[j]-lst[j-1])
        z = min(z, lst[j]-lst[j-1])    
    print(y, -z)

Submission status: Accepted

Solution code:
t = int(input())
for i in range(t):
    n = int(input())
    li = [int(x) for x in input().split()]
    a, b = 0, 0
    for j in range(1, n):
        a = max(a, li[j]-li[j-1])
        b = min(b, li[j]-li[j-1])
    print(a, -b)

Submission status: Accepted

Solution code:
def saizo(A:list):

	uplen = 0
	downlen = 0
	num = len(A)

	for j in range(num-1):
		tmp = A[j+1] - A[j]
		if A[j+1] >= A[j]:
			uplen = max(uplen,tmp)
		else:
			downlen = max(downlen,abs(tmp))
			
	print(uplen,downlen)


if __name__ == '__main__':

	n = int(input())
	for i in range(n):
		input()
		saizo(list(map(int,input().split())))

Submission status: Accepted

Solution code:
t = int(input())

for _ in range(t):
    n = int(input())
    block = list(map(int, input().split()))

    diff = []
    for i in range(len(block) - 1):
        d = block[i+1] - block[i]
        diff.append(d)

    up = max(0, max(diff))
    down = abs(min(0, min(diff)))
    print(up, down)

Submission status: Runtime Error

Solution code:
t = int(input())
for _ in range(t):
    n = int(input())
    h = list(map(int, input().split()))
    maxv = 0, minv = 0
    for i in range(len(h)-1):
        maxv = max(maxv, h[i+1]-h[i])
        minv = max(minv, h[i]-h[i+1])
    print(maxv, minv)

Submission status: Runtime Error

Solution code:
import sys

def solve():
    c = int(raw_input())
    for i in range(c):
        n = int(raw_input())
        data = map(int, raw_input())
        u,d = 0,0
        for i in range(n - 1):
            if i % 2 == 0:
                if data[i + 1] - data[i] > u:
                    u = data[i + 1] - data[i]
            else:
                if data[i + 1] - data[i] > d:
                    d = data[i + 1] - data[i]
    print u,d

if __name__ == "__main__":
    solve()