LoginSignup
0
0

More than 1 year has passed since last update.

ABC176 C - Step を解いた

Last updated at Posted at 2021-10-15

abc176c_1.png
abc176c_2.png
abc176c_3.png

abc176c.py
N = int(input())
lis = list(map(int,input().split()))
score = 0
ref = lis[0]

for i in range(1,N):
    if ref > lis[i]:
        score += ref-lis[i]
    else:
        ref = lis[i]

print(score)#110ms

for i in range(N) で リスト内の値を呼び出すより、
for a in lis というように直接代入する方が速い。
また、if , elif を使うよりは if,else で完結した方がより速い。

abc176c_r1.py
def solv0():
    _ =int(input())
    A = list(map(int,input().split()))
    cnt = 0
    max_hight = 0
    for hight in A:
        if max_hight < hight:
            max_hight = hight
        elif max_hight > hight:
            cnt += max_hight-hight
    return cnt

def solv1():
    _ =int(input())
    A = list(map(int,input().split()))
    cnt = 0
    max_hight = 0
    for hight in A:
        if max_hight <= hight:
            max_hight = hight
        else:
            cnt += max_hight-hight
    return cnt

#print(solv0()) #86ms
print(solv1()) #80ms
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0