AcWing 100. 【Python】IncDec序列
原题链接
中等
作者:
tt2767
,
2019-12-15 00:59:27
,
所有人可见
,
阅读 729
import sys
import re
def read(raw):
sbuffer = list()
for s in raw:
if re.match('\s', s) is None:
sbuffer.append(s)
elif len(sbuffer) > 0:
yield ''.join(sbuffer)
sbuffer = list()
yield ''.join(sbuffer)
pin = read(sys.stdin.read())
n = int(pin.next())
a = [0] * (n+1)
b = [0] * (n+1)
for i in range(n):
a[i+1] = int(pin.next())
for i in reversed(range(1, n+1)):
a[i] -= a[i-1]
pos = sum(filter(lambda x: x > 0, a[2:]))
neg = sum(filter(lambda x: x < 0, a[2:])) * -1
print max(pos, neg)
print abs(pos-neg)+1