Problem:


  MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Maximum Profit

You can obtain profits from foreign exchange margin transactions. For example,  if you buy 1000 dollar at a rate of 100 yen per dollar, and sell them at a rate of 108 yen per dollar, you can obtain (108 - 100) &times; 1000 = 8000 yen.

  Write a program which reads values of a currency $R_t$ at a certain time $t$ ($t = 0, 1, 2, ... n-1$), and reports the maximum value of $R_j - R_i$ where $j > i$ .

Input

The first line contains an integer $n$. In the following $n$ lines, $R_t$ ($t = 0, 1, 2, ... n-1$) are given in order.

Output

Print the maximum value in a line.

Constraints

  
$2 \leq n \leq 200,000$

  
$1 \leq R_t \leq 10^9$

Sample Input 1

6
5
3
1
3
4
3

Sample Output 1

3

Sample Input 2

3
4
3
2

Sample Output 2

-1



Sample input:
6
5
3
1
3
4
3


Sample output:
3

Submission status: Accepted

Solution code:
n = int(input())
s = []
while(n>0):
    s.append(int(input()))
    n -= 1

mi = 10e9
ma = -10e9

for i in range(len(s)-1):
    mi = min(mi,s[i])
    ma = max(ma,s[i+1] - mi)
    
print(ma)

Submission status: Accepted

Solution code:
N = int(input())

minv = int(input())
maxv = -20000000000
for i in range(N - 1):
  v = int(input())
  maxv = max(maxv, v - minv)
  minv = min(minv, v)
print(maxv)

Submission status: Accepted

Solution code:
a = int(input())

N = []

for i in range(a):
    b = int(input())
    N.append(b)

max_n = -10000000000000000
min_n = N[0]

for i in range(1,a):
    max_n = max(max_n, N[i]-min_n)
    min_n = min(min_n, N[i])

print(max_n)

Submission status: Accepted

Solution code:
n = int(input())
ma, mi = -10**10, 10**10

for _ in range(n):
    x = int(input())
    ma, mi = max(ma, x - mi), min(mi, x)
print(ma)

Submission status: Accepted

Solution code:
n = int(input())
rList = [int(input()) for i in range(n)]
minR = rList[0]
maxDiff = -10**9
for i in range(1, n):
    maxDiff = max(maxDiff, rList[i] - minR)
    minR = min(minR, rList[i])
print(maxDiff)

Submission status: Accepted

Solution code:
n = int(input())
r = [int(input()) for _ in range(n)]


max_num = 1 - 10**9
min_num = r[0]
for i in range(1,n):
    max_num = max(max_num, r[i]-min_num)
    min_num = min(min_num, r[i])
print(max_num)

Submission status: Accepted

Solution code:
n = int(input())

R = []
for i in range(n):
    R.append(int(input()))

maxv = R[1]-R[0]
minv = R[0]

for j in range(1,n):
    if maxv < R[j] - minv:
        maxv = R[j] - minv
    if minv > R[j]:
        minv = R[j]

print(maxv)

Submission status: Accepted

Solution code:
n = int(input())
max_profit = -float('inf')
min_price = float('inf')
for _ in range(n):
    price = int(input())
    if max_profit < price - min_price:
        max_profit = price - min_price
    if min_price > price:
        min_price = price
print(max_profit)

Submission status: Accepted

Solution code:
num=[]
for i in range(int(input())):
	num.append(int(input()))
	if i==0:
		min=num[0]
	elif i==1:
		max=num[1]-num[0]
		if num[1]<min:
			min=num[1]
	else:
		if num[i]-min>max:
			max=num[i]-min
		elif num[i]<min:
			min=num[i]
print(max)

Submission status: Accepted

Solution code:
N = int(input())
r = [int(input()) for i in range(N)]

tmp_max = r[1] - r[0]
tmp_min = r[0]

for i in range(N-1):
  if(r[i+1] - tmp_min > tmp_max):
    tmp_max = r[i+1] - tmp_min
  if(r[i+1] < tmp_min):
    tmp_min = r[i+1]

print(tmp_max)

Submission status: Accepted

Solution code:
import math

n=int(input())
t=int(input())
mint=t
t1=int(input())
if t1<t: mint=t1
maxtt=t1-t


for i in range(2,n):
    t=int(input())
 
    if t-mint>maxtt: maxtt=t-mint
    if t<mint: mint=t
    
print(int(maxtt))

Submission status: Accepted

Solution code:
n = int(input())
Min = int(input())
Max = -10**9
for i in range(n):
    if i > 0:
        Num = int(input())
        if Max < Num - Min:
            Max = Num - Min
        
        if Min > Num:
            Min = Num
        
print(Max)

Submission status: Accepted

Solution code:
N = int(input())
lst = []


for i in range(N):
  lst.append(int(input()))

M = lst[1] - lst[0]
m = lst[0]

for j in range(1, N):
    M = max([M, lst[j] - m])
    m = min([m, lst[j]])
            
print(M)

Submission status: Accepted

Solution code:
b = int(input())
n = []
ans = -2**100

for i in range(b):
    a = int(input())
    n.append(a)
minn = n[0]

for i in range(1,b):
    ans = max(ans, n[i]-minn)  
    minn = min(minn, n[i])     
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
m=int(input())
l=int(input())
ma=l-m
mi=min(l,m)
for i in range(n-2):
    j=int(input())
    ma=max(ma,j-mi)
    mi=min(mi,j)
print(ma)

Submission status: Accepted

Solution code:
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_D&lang=jp

def main():
    n = int(input())
    N = [int(input()) for _ in range(n)]
    
    # O(n)
    minv = N[0]
    maxv = -10000000000000000
    for i in range(1, len(N)):
        maxv = max(maxv, N[i] - minv)
        minv = min(minv, N[i])
    print(maxv)

main()

Submission status: Accepted

Solution code:
import sys
# import bisect
# import math
# import itertools
# import numpy as np
# import collections

"""Template"""


class IP:
    """
    入力を取得するクラス
    """

    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        # 参考
        # https://blog.rossywhite.com/2018/08/06/bit-search/
        # https://atcoder.jp/contests/abc105/submissions/4088632
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    # output.append(a[j])
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x // y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

    def gcd(self, x, y):
        if y == 0:
            return x
        else:
            return self.gcd(y, x % y)


"""ここからメインコード"""


def main():
    # 1文字に省略
    r, e, p = range, enumerate, print
    ip = IP()
    id = Idea()
    mod = 10 ** 9 + 7

    """この下から書いてね"""
    n = ip.I()
    ma = -1e11
    mi = 1e11
    for _ in r(n):
        r = ip.I()
        ma, mi = max(ma, r - mi), min(mi, r)
    p(ma)


main()

Submission status: Accepted

Solution code:
n = int(input())

num = []
max = -9999999999999
minv = 10000000000

for i in range(n):
    num.append(int(input()))

    if i >= 1:
        if max <= num[i] - minv:
            max = num[i] - minv

    if num[i] <= minv:
         minv = num[i]

print(max)

Submission status: Accepted

Solution code:
n = int(input())
r = [int(input()) for i in range(n)]
minp = r[0]
pft = r[1] - r[0]
for i in range(1, n):
    pft = max(pft, r[i] - minp)
    minp = min(minp, r[i])

print(pft)

Submission status: Accepted

Solution code:
n = int(input())
high, low , max = 0, 1000000000, -1000000000
for i in range(n):
    a = int(input())
    if high < a and i > 0:
        high = a
    if max < high - low:
        max = high - low
    if low > a:
        low, high = a, 0
print(max)

Submission status: Accepted

Solution code:
n = int(input())
R = [int(input()) for _ in range(n)]

min_R = R[0]
profit = -2000000000

for i in range(1, n):
    profit = max(profit, R[i] - min_R)
    min_R = min(min_R, R[i])

print(profit)

Submission status: Accepted

Solution code:
n = int(input())
r = []
for i in range(n):
    r.append(int(input()))

maxv = -2 * 10**9
minv = r[0]

for i in range(1, n):
    maxv = max(maxv, r[i]-minv)
    minv = min(minv, r[i])

print(maxv)

Submission status: Accepted

Solution code:
n = int(input())
min_v=int(input())
max_v=int(input())
hold_R=max_v-min_v
min_v=min(min_v, max_v)
for i in range(n-2):
    r_t=int(input())
    hold_R = max(hold_R, r_t-min_v)
    min_v = min(min_v, r_t)
print(hold_R)

Submission status: Accepted

Solution code:
n = int(input())
r = int(input())
rr = int(input())

ans = rr- r
ma, mi = max(r, rr), min(r, rr)

for _ in range(n - 2):
    R = int(input())
    ans = max(R - mi, ans)
    
    ma = max(ma, R)
    mi = min(mi, R)
    
    
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
ans = -float('INF')
num = [int(input()) for _ in range(n)]
mini = float('INF')
for i in range(1, n):
    mini = min(mini, num[i-1])
    tmp = num[i] - mini
    ans = max(ans, tmp)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
rmax = -2000000000
rmin = int(input())
for _ in range(2,n+1):
    r = int(input())
    rmax = max(r-rmin, rmax)
    rmin = min(rmin, r)
print (rmax)

Submission status: Accepted

Solution code:
n = int(input())
r = [int(input()) for i in range(n)]
maxv = -(10**9)
minv = 10**9
for i in range(1,n):
    if minv > r[i-1]:
        minv = r[i-1]
    if r[i] - minv > maxv:
        maxv = r[i] - minv
print(maxv)

Submission status: Accepted

Solution code:
time = int(input())
min = int(input())
diff = -999999999
for i in range(time-1):
    value = int(input())
    math = value - min
    if math > diff:
        diff = math

    if value < min:
        min = value
print(diff)

Submission status: Accepted

Solution code:
n = int(input())
r = [int(input()) for i in range(n)]
min_r = r[0]
max_d = r[1]-r[0]
for i in range(1,n):
    max_d = max(max_d, r[i] - min_r)
    min_r = min(min_r, r[i])
print(max_d)

Submission status: Accepted

Solution code:
n = int(input())

maxv = -200000000000000
minv = int(input())

for i in range(1,n):
    R = int(input())
    maxv = max(maxv, R-minv)
    minv = min(minv, R)

print(maxv)

Submission status: Accepted

Solution code:
n,*a=map(int,open(0).read().split())
ans=-99999999999999999999
mini=a[0]
for i in range(n-1):
    if a[i]<mini:
        mini=a[i]
    if a[i+1]-mini>ans:
        ans=a[i+1]-mini
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
r = [int(input()) for i in range(n)]

m = r[n-1]
ans = -10**10
for i in range(n-2, -1, -1):
    t = m-r[i]
    if t > ans:
        ans = t
    if r[i] > m:
        m = r[i]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
nums = []
for i in range(n):
    nums.append(int(input()))

max_profit = nums[1] - nums[0]
min_price = nums[0]

for time in range(1, n):
    profit = nums[time] - min_price
    if profit > max_profit:
        max_profit = profit
    if nums[time] < min_price:
        min_price = nums[time]

print(max_profit)

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-

N = int(input())

first_plice = int(input())
second_plice = int(input())
min_plice = min(first_plice, second_plice)
max_profit = second_plice - first_plice

for i in range(N-2):
    next_plice = int(input())
    max_profit = max(max_profit, next_plice - min_plice)
    min_plice = min(min_plice, next_plice)    

print(max_profit)

Submission status: Accepted

Solution code:
n = int(input())
maxv = -2000000000
rr = [0]*n
for i in range(n):
    rr[i] = int(input())
minv = rr[0]
for i in range(1,n):
    r = rr[i]
    maxv = max([maxv, r - minv])
    minv = min([minv, r])
print(maxv)

Submission status: Accepted

Solution code:
n = int(input())
x=[]
for i in range(n):
   x.append(int(input()))
maxv = x[1] - x[0]
minv = x[0]
for i in range(1, n):
    if maxv <= x[i] - minv:
        maxv = x[i] - minv
    if minv >= x[i]:
        minv = x[i]
print(maxv)

Submission status: Accepted

Solution code:
n = int(input())
min_r = pow(10, 10)
max_r = -pow(10,10)
for i in range(n):
    r = int(input())
    max_r = max(max_r,r - min_r)
    min_r = min(min_r, r)
print(max_r)

Submission status: Accepted

Solution code:
n = int(input())
r_list = [int(input()) for i in range(n)]
minv = r_list[0]
maxv= -10**9
for i in range(1,n):
        maxv = max(r_list[i]-minv, maxv)
        minv = min(minv,r_list[i])

print(maxv)

Submission status: Accepted

Solution code:
n = int(input())
R = [int(input()) for _ in range(n)]
ans = R[1] - R[0]
bottom = min(R[0], R[1])
for r in R[2:]:
    ans = max(ans, r - bottom)
    if r < bottom:
        bottom = r
print(ans)

Submission status: Accepted

Solution code:
t = int(input())
early_value = int(input())
for i in range(t-1):
	value = int(input())
	if not i:
		later_value = value
		profit = later_value - early_value
		#print('Profit seted:', profit)
		#has_lesser = False
	if value < early_value:
		early_value = value
		#has_lesser = True
	#elif has_lesser:
		#if profit < value - early_value:
			#later_value = value
			#profit = later_value - early_value
			#print('Profit changes:', profit)
	elif profit < value - early_value:
		later_value = value
		profit = later_value - early_value
		#print('Profit changes:', profit)
print(profit)

Submission status: Accepted

Solution code:
def main():
    max_p = -1_000_000_000
    n = int(input())
    min_v = int(input())

    for i in range(1, n):
        now_v = int(input())
        now_p = now_v - min_v
        if max_p < now_p:
            max_p = now_p
        if now_v < min_v:
            min_v = now_v

    print(max_p)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = input()
R_min = input()
R_max = 0
diff_max = R_max - R_min

R = R_min
for i in range(0, N-1):
    R = input()
    a = R - R_min
    if diff_max < a:
        diff_max = a
    if R < R_min:
        R_min = R

print(diff_max)

Submission status: Accepted

Solution code:
# coding: utf-8
import sys

n = int(input().rstrip())
ans = - sys.maxsize
minimum = sys.maxsize
for i in range(n):
    r = int(input().rstrip())
    if r - minimum > ans:
        ans = r - minimum
    if r < minimum:
        minimum = r

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
minR = int(input())
maxVal = -10**9-1
for i in range(n-1):
    po = int(input())
    maxVal = max(maxVal, po - minR)
    minR = min(minR, po)
print(maxVal)

Submission status: Accepted

Solution code:
N = int(input())
maxv = -1000000000
minv = int(input())
for i in range(1,N):
    n = int(input())
    maxv = max(maxv,n-minv)
    minv = min(minv,n)
print(maxv)

Submission status: Accepted

Solution code:
mn = 0
max_range = -1000000000
n = int(input())
mn = int(input())
for i in range(n-1):
    m = int(input())
    if m - mn > max_range:
      max_range = m - mn
    if m < mn:
      mn = m
print(max_range)

Submission status: Accepted

Solution code:
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_D&lang=jp

n = int(input())
maximum = -10e10
minimum = 10e10
# maximum, minimum = max(maximum, minimum), min(maximum, minimum)
maxmin = []
prev_num = 10e10
max_diff_between_two = -10e10
for i in range(n):
    in_num = int(input())
    if in_num - prev_num > max_diff_between_two and prev_num != 10e10:
        max_diff_between_two = in_num - prev_num
    if in_num < minimum:
        if maximum != -10e10 and minimum != 10e10:
            maxmin.append(maximum - minimum)
        minimum = in_num
        maximum = -10e10
    elif in_num > maximum:
        maximum = in_num
    prev_num = in_num
if maximum != -10e10 and minimum != 10e10:
    maxmin.append(maximum - minimum)

if len(maxmin) == 0:
    print(max_diff_between_two)
    quit()

max_diff = -10e10
for i in maxmin:
    if max_diff < i:
        max_diff = i

print(max_diff)

Submission status: Accepted

Solution code:
n = int(input()) 
list_R = [] 
for i in range(n):
    list_R.append(int(input()))

maxv = -20000000000000000
minv = list_R[0]

for j in range(1,n):
    if maxv < list_R[j]-minv:
        maxv = list_R[j]-minv
    if minv > list_R[j]:
        minv = list_R[j]
print(maxv)

Submission status: Accepted

Solution code:
n = int(input())
R = []
for i in range(n):
    R.append(int(input()))

maxv = -1000000000
minv = R[0]

for i in range(1,n):
    if maxv < R[i] - minv:
        maxv = R[i] - minv
    if minv > R[i]:
        minv = R[i]

print(maxv)

Submission status: Accepted

Solution code:
n = int(input())
val = [0] * n
maxdiff = [0] * n
for i in range(n):
    val[i] = int(input())
maxdiff[0] = 0
maxdiff[1] = val[1] - val[0]
minval = min(val[0:2])
for i in range(2, n):
    maxdiff[i]= max(maxdiff[i - 1], val[i] - minval)
    minval = min(minval, val[i])
print(maxdiff[-1])

Submission status: Accepted

Solution code:
n = int(input())
R = [int(input()) for l in range(n)]

max_profit = -(10**10)
R_min = R[0]

for j in range(1, n):
    if R[j] - R_min > max_profit:
        max_profit = R[j] - R_min
    if R[j] < R_min:
        R_min = R[j]

print(max_profit)

Submission status: Accepted

Solution code:
num = int(input())
a = int(input())
b = int(input())
ans = b - a
temp = min(a, b)

for i in range(num - 2):
        num = int(input())
        if ans < num - temp:
                ans = num - temp
        if temp > num:
                temp = num

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
rate = [int(input()) for _ in range(n)]
maxProfit = rate[1] - rate[0]
minRate = rate[0]  # 最小レートを記録
maxRate = rate[0]  # 最小レート更新後の最大レートを記録
for i in range(1, n):
    # 最小レートを更新したらそれ以降の最大レートとの最大利益と前の最大利益を比べる
    if rate[i] < minRate:
        minRate = rate[i]
        maxRate = rate[i]
    elif rate[i] >= maxRate and rate[i] - minRate > maxProfit:
        maxProfit = rate[i] - minRate
print(maxProfit)

Submission status: Accepted

Solution code:
N = int(input())
R = [int(input()) for _ in range(N)]

max_res = -1e9
min_R = R[0]

for j in range(1, N):
    R_j = R[j]
    max_res = max(max_res, (R_j - min_R))
    min_R = min(min_R, R_j)

print(max_res)

Submission status: Accepted

Solution code:
n = int(input())
r = [int(input()) for _ in range(n)]
maxv = r[1] - r[0]
minv = r[0]
for i in range(1, n):
    maxv = max(maxv, r[i] - minv)
    minv = min(minv, r[i])
print(maxv)

Submission status: Accepted

Solution code:
#利益を最大

N = int(input())
a = [int(input()) for i in range(N)]

d_MAX = -2*10**9
v_min = a[0]

for i in range(1, N):
    d_MAX = max(d_MAX, a[i]-v_min)
    v_min = min(v_min, a[i])

print(d_MAX)

Submission status: Accepted

Solution code:
n = int(input())
R = [int(input()) for _ in range(n)]

min_R = R[0]
max_D = R[1] - R[0]
for i in range(1, n):
    max_D = max(max_D, R[i] - min_R)
    min_R = min(min_R, R[i])

print(max_D)

Submission status: Accepted

Solution code:
n=int(input())
mi=int(input())
ans=-float('inf')
for i in range(n-1):
    new=int(input())
    ans=max(ans,new-mi)
    mi=min(mi,new)
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
r_min=int(input())
r_t=int(input())
g_max=r_t-r_min
r_min=min(r_t,r_min)

for _ in range(n-2):
    r_t=int(input())
    g_max=max(g_max,r_t-r_min)
    r_min=min(r_t,r_min)

print(g_max)

Submission status: Accepted

Solution code:
import math

n = int(input())
R = [int(input()) for _ in range(n)]

maxv = -math.inf
minv = R[0]
for i in range(1, n):
    diff = R[i] - minv
    maxv = diff if diff > maxv else maxv
    minv = R[i] if R[i] < minv else minv

print(maxv)

Submission status: Accepted

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
R = [int(stdin.readline().rstrip()) for i in range(n)]
minval = R[0]
diff = R[1]-minval
for i in range(1, n):
    diff = max(diff, R[i]-minval)
    minval = min(minval, R[i])
    
print(diff)

Submission status: Accepted

Solution code:
n = int(input())
li = [int(input()) for _ in range(n)]
minv = li[0]
maxv = 10**9*(-1)

for i in range(1,n):
    maxv = max(maxv,li[i]-minv)
    minv = min(minv,li[i])

print(maxv)

Submission status: Accepted

Solution code:
import sys
mx = -sys.maxsize - 1
mi = sys.maxsize
for i in range(int(input())):
    x1 = int(input())
    mx = max(mx, x1 - mi)
    mi = min(mi, x1)
print(mx)

Submission status: Accepted

Solution code:
n = int(input())

minv = int(input())
maxp = -1 * 10 ** 9
for _ in range(n - 1):
    tmp = int(input())
    maxp = max(maxp, tmp - minv)
    minv = min(minv, tmp)

print(maxp)

Submission status: Accepted

Solution code:
import sys
import math

n = int(sys.stdin.readline())

profit = -math.inf
lowest = math.inf
for _ in range(n):
    r = int(sys.stdin.readline())
    profit = max(profit, r - lowest)
    lowest = min(lowest, r)

print(profit)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
	n = int(input())
	R = [int(input()) for i in range(n)]

	minv = R[0]
	maxv = R[1] - R[0]
	for j in range(1, n):
		if (maxv < R[j] - minv):
			maxv = R[j] - minv
		if (R[j] < minv):
			minv = R[j]
	print(maxv)

Submission status: Accepted

Solution code:
n = int(input())
R, maxv = [], None
for _ in range(n):
    R.append(int(input()))
minv = R[0]
for j in range(1,n):
    maxv = max(maxv, R[j]-minv) if maxv else R[j]-minv
    minv = min(minv, R[j])
print(maxv)

Submission status: Accepted

Solution code:
n = int(input())
min_number = int(input())
max_profit = -2000000000000000000000000000
for i in range(n-1):
    number = int(input())    
    if max_profit < number-min_number:
        max_profit = number - min_number
    if number < min_number:
        min_number = number
print(max_profit)

Submission status: Accepted

Solution code:

if __name__ == "__main__":
    n = int(input())
    R = []
    for i in range(0,n,1):
        R.append(int(input()))
    maxv = R[1] - R[0]
    minv = R[0]
    for i in range(1,n,1):
        maxv = max(maxv, R[i]-minv)
        minv = min(minv,R[i])
    print(maxv)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]

maxv = -float('inf')
minv = a[0]

for i in range(1, n):
    maxv = max(maxv, a[i] - minv)
    minv = min(minv, a[i])

print(maxv)

Submission status: Accepted

Solution code:
n = int(input())

ans = -10000000000000000000
mn = 1000000000000000000
for i in range(n):
    x = int(input())
    ans = max(ans, x - mn)
    mn = min(mn, x)

print(ans)

Submission status: Accepted

Solution code:
n = int(input().strip())
r = [int(input().strip()) for _ in range(n)]
minv = r.pop(0)
maxv = -10**9
for ri in r:
    maxv = max(maxv, ri-minv)
    minv = min(minv, ri)
print(maxv)

Submission status: Accepted

Solution code:
def main():
	n = int(input())
	r = [int(input()) for _ in range(n)]
	rmax = r[1] - r[0]
	rmin = r[0]
	for i in range(1, n):
		rmax = max(rmax, r[i] - rmin)
		rmin = min(r[i], rmin)
	print(rmax)

main()

Submission status: Accepted

Solution code:
a,b=-1e11,1e11
for i in range(int(input())):
    c=int(input())
    a,b=max(a,c-b),min(b,c)
print(a)

Submission status: Accepted

Solution code:
n = int(input())
count = 0
l = []

for i in range(0, n):
    b = int(input())
    l.append(b)

maxv = l[1]-l[0]
minv = l[0]

for i in range(1,n):
    maxv = max(maxv, l[i]-minv)
    minv = min(minv, l[i])

print(maxv)

Submission status: Accepted

Solution code:
n=int(input())
mini=int(input())
maxv=-float("inf")
for i in range(n-1):
    x=int(input())
    maxv=max(maxv,x-mini)
    mini=min(mini,x)
print(maxv)

Submission status: Accepted

Solution code:
n=int(input())

sabun=0
for i in range(n):
    r=int(input())
    if i>=1:
        sabun=r-min_r
        if i==1:
            saidai=sabun
        if sabun>saidai:
            saidai=sabun
    if i==0:
        min_r=r
    elif r<min_r:
        min_r=r

print(saidai)

Submission status: Accepted

Solution code:
n=int(input())
t=int(input())
t1=int(input())
maxim=t1-t
if t<=t1:
    max_i=t1
    min_i=t
else:
    min_i=t1
    max_i=t
if n>2:
    for i in range(2,n):
        t=int(input())
        if t-min_i>maxim:
            maxim=t-min_i
        if t>max_i:
            max_i=t
        elif t<min_i:
            min_i=t
print(maxim)

Submission status: Accepted

Solution code:
n = int(input())

min_num = int(input())
max_num = 0
profit = -999999999

for i in range(0, n - 1):
    num = int(input())
    temp = num - min_num
    if temp > profit:
        profit = temp
    if num < min_num:  
        min_num = num
        max_num = num
    if num > max_num:
        max_num = num

print(profit)

Submission status: Accepted

Solution code:
n = int(input())
r0 = int(input())
r1 = int(input())
mx = r1 - r0
mn = min(r0, r1)

for i in range(2, n):
    r = int(input())
    mx = max(mx, r - mn)
    mn = min(r, mn)

print(mx)

Submission status: Accepted

Solution code:
def solve():
    loop = int(input())
    profit = 1 - 10 ** 9

    current_min = int(input())
    for _ in range(loop-1):
        now = int(input())
        if now - current_min > profit:
            profit = now - current_min

        if current_min > now:
            current_min = now
    print(profit)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

N = int(input())
aN = [int(input()) for i in range(N)]

start = aN[0]
ans = -float('inf')
for i in range(1,N):
    # 今-起点と今までの最大を比較
    ans = max(aN[i] - start, ans)
    # 最安値の更新したら起点を変える
    start = min(aN[i], start)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
num_list = [int(input()) for _ in range(n)]
max_num = 10**9*-1
min_num = num_list[0]

for i in range(1,len(num_list)):
    max_num = max(num_list[i]-min_num,max_num)
    min_num = min(num_list[i],min_num)

print(max_num)

Submission status: Accepted

Solution code:
#Maximum Profit
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_D&lang=jp

n = int(input())
min = int(input())
profit = -999999999

for i in range(0,n-1):
    s = int(input())
    if (s - min > profit):
        profit = s - min
    if (min > s):
        min = s
print (profit)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    nums = [int(input()) for i in range(n)]

    maxv = nums[1]-nums[0]
    minv = nums[0]

    for i in range(1, n):
        if maxv < nums[i]-minv:
            maxv = nums[i]-minv
        if minv > nums[i]:
            minv = nums[i] 
   
    print(maxv)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n=int(input())
minR=int(input())
R=[int(input()) for i in range(n-1)]
maximum=R[0]-minR
for r in R:
    maximum=max(maximum, r-minR)
    minR=min(minR, r)
print(maximum)

Submission status: Accepted

Solution code:
n = int(input())

rlist = []
for _ in range(n):
    rlist.append(int(input()))

ans = rlist[1] - rlist[0]
m = rlist[0]

for i in range(1, n):
    ans = max(ans, rlist[i] - m)
    m = min(m, rlist[i])

print(ans)

Submission status: Accepted

Solution code:
#import sys

#input1 = [6,5,3,1,3,4,3]

#input2 = [3,4,3,2]

# Input Select Flag
#inputselflag = 1

#if inputselflag == 1:
#    inputs = input1[1:]
#elif inputselflag == 2:
#    inputs = input2[1:]
#else:
#    sys.exit()

# Calc
#for i in range(1, len(inputs)-1):
    #print(inputs[i-1])
    #result.append([inputs[i+1] - inputs[i]])
   #for j in range(i+1, len(inputs)):
        #print(inputs[j])
        #print(inputs[i])
        #print('\n')
        #result.append([inputs[j] - inputs[i]])
        #print(result[j-1])

import sys

def main():
    inputs = int(sys.stdin.readline().rstrip())
    maxv = -100000000000
    minv = int(sys.stdin.readline().rstrip())

    # Calc idel
    for i in range(1, inputs):
        compv = int(sys.stdin.readline())
        if compv - minv > maxv:
            maxv = compv - minv
        if compv < minv:
            minv = compv
        

    bigprice = maxv
    print(bigprice)



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=[]
for i in range(int(input())):
	n.append(int(input()))
n_min=n[0]
n_max=n[1]-n_min
for i in range(1,len(n)):
	if n_max<n[i]-n_min:
		n_max=n[i]-n_min
	if n_min>n[i]:
		n_min=n[i]
print(n_max)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
ans = -10 ** 9
minnum = a[0]
for i in range(1, n):
	ans = max(ans, a[i] - minnum)
	minnum = min(minnum, a[i])
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
minv = int(input())
maxv = -2000000000
for i in range(n-1):
    ri = int(input())
    b = [maxv, ri-minv]
    maxv = max(b)
    a = [minv, ri]
    minv = min(a)
print(maxv)

Submission status: Accepted

Solution code:
N = int(input())
r0, r1 = int(input()), int(input())
if r0 < r1:
    mint = r0
else:
    mint = r1
d = r1 - r0
for c in range(N-2):
    rj = int(input())
    dj = rj - mint
    if dj > d:
        d = dj
    if rj < mint:
        mint = rj
print(d)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    n = int(input())
    lst = [int(input()) for x in range(n)]
    max_lst = []
    tmpmax = 0
    for i in range(1, n + 1):
        tmpmax = max(tmpmax, lst[-i])
        max_lst.append(tmpmax)
    maxA = -(10 ** 9 + 1)
    for i in range(n - 1):
        maxA = max(maxA, max_lst[-i-2] - lst[i])
    print(maxA)

Submission status: Accepted

Solution code:
max_p=-10**11
n=int(input())
min_r=int(input())
for i in range(n-1):
    r = int(input())
    p = r-min_r
    if p>max_p:
        max_p = p
    if r<min_r:
        min_r = r
    print
print(max_p)