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: Wrong Answer

Solution code:
values = [int(input()) for i in range(int(input()))]
maxv = -200000
minv = values[0]

for val in values:
    maxv = max(maxv, (val - minv))
    minv = min(minv, val)         # 今までの最小値を保持(自分と自分を比較しない様に、最大値の評価後に計算)
print("{:d}".format(maxv))

Submission status: Wrong Answer

Solution code:
n=int(input())
A=[0]*n
gap=0
for i in range(n):
    A[i]=int(input())
for i in range(1,n):
    for j in range(0,i):
        tmp=A[i]-A[j]
        if abs(tmp)>gap:
            gap=tmp
print(gap)

Submission status: Wrong Answer

Solution code:
#16D8101012J 伊藤惇 dj Python3

def Maximum_Profit(n,A):
    Max=A[1]-A[0]
    Min=A[0]
    for j in range(1,n-1):
        Max=max(Max,A[j]-Min)
        Min=min(Min,A[j])
    return Max

if __name__ == "__main__":
    n=int(input())
    A=[]
    for i in range(n):
        A.append(int(input()))
    Max=Maximum_Profit(n,A)
    print(Max)

Submission status: Wrong Answer

Solution code:


n=int(input())

list=[int(input()) for i in range(n)]

max1=list[1]-list[0]

for i in range(n):
	x=(max(list)-list[0])
	if x>max1:
		max1=x
	list.remove(list[0])
#	print(list)



print(max1)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]

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

Submission status: Wrong Answer

Solution code:
def parse_stdin(input_lines: int):
    data_list = []
    for i in range(input_lines):
        data_list.append(input().rstrip())
    return data_list


def find_max_interest(rates):
    min_value = rates[0]
    max_interest = -200000000
    for i, rate in enumerate(rates[1:]):
        max_interest = max(max_interest, rate - min_value)
        min_value = min(min_value, rate)
    return max_interest


def main():
    input_lists = parse_stdin(int(input()))
    rates = list(map(int, input_lists))
    print(find_max_interest(rates))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [0]*n
for i in range(n):
    a[i] = int(input())

max = a[1]-a[0]
for i in range(2,n):
    for j in range(0,i-1):
        tmp = a[i]-a[j]
        if max<tmp:
            max = tmp

print(max)

Submission status: Wrong Answer

Solution code:

def Maximum(R,n):
	Max=R[1]-R[0]
	Min=R[1]
	for i in range(2,n):
		tmp=R[i]-Min
		if Max<tmp:
			Max=tmp
		if Min>R[i]:
			Min=R[i]
	
	return Max

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

print(Max)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = [int(input()) for i in range(n)]
max = A[1]-A[0]

for i in range(1,n-1):
    if(max < A[i+1]-A[i]):
        max = A[i+1]-A[i]

print(max)

Submission status: Wrong Answer

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

for i in range(1,n-1):
    if(min > A[i]):
        ss = i
for i in range(ss,n-1):
    if(max < A[i+1]-A[ss]):
        max = A[i+1]-A[ss]
print(max)

Submission status: Wrong Answer

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

for i in range(1,n-1):
    if(min > A[i]):
        ss = i
        for i in range(ss,n-1):
            if(max < A[i+1]-A[ss]):
                max = A[i+1]-A[ss]
print(max)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = [int(input()) for i in range(n)]
max = A[1]-A[0]
min = A[0]
j = 0

for i in range(1,n-1):
    if(min > A[i]):
        for j in range(j,n-1):
            if(max < A[j+1]-A[i]):
                max = A[j+1]-A[i]
print(max)

Submission status: Wrong Answer

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

for i in range(1,n-2):
    if(min > A[i]):
        for j in range(i,n-1):
            if(max < A[j+1]-A[i]):
                max = A[j+1]-A[i]
print(max)

Submission status: Wrong Answer

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

for i in range(n-1):
    if(max < A[i+1]-A[0]):
        max = A[i+1]-A[0]

for i in range(1,n-2):
    if(min > A[i]):
        for j in range(i,n-1):
            if(max < A[j+1]-A[i]):
                max = A[j+1]-A[i]
print(max)

Submission status: Wrong Answer

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

for i in range(1,n-1):
    if(max < A[i]-min):
        max = A[i]-min
    if(min > A[i]):
        min = A[i]

print(max)

Submission status: Wrong Answer

Solution code:
n=int(input())
maxn=0
minn=int(input())

for j in range(1, n):
    r = int(input())
    maxn = max(maxn, r - minn)
    minn = min(minn, r)
    
print(maxn)

Submission status: Wrong Answer

Solution code:
n=int(input())
maxn=-1
minn=int(input())

for j in range(1, n):
    r = int(input())
    maxn = max(maxn, r - minn)
    minn = min(minn, r)
    
print(maxn)

Submission status: Wrong Answer

Solution code:
#! python3
# maximum_profit.py

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

maximum_profit = R[-1]-R[-2]
min_i = R[0]
for i in range(n-2):
    if R[i] >= min_i: continue
    max_profit_i = R[i+1]-R[i]
    for j in range(i+2, n):
        tmp = R[j]-R[i]
        if max_profit_i < tmp:
            max_profit_i = tmp
    if maximum_profit < max_profit_i:
        maximum_profit = max_profit_i
print(maximum_profit)

Submission status: Wrong Answer

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

price = [int(input()) for p in range(int(input()))]
# print("price:", price)

# 利益差のみで計算する
diff = list()

for i in range(len(price) - 1):
    diff.append(price[i + 1] - price[i])
# print("diff:", diff)

summary = diff[0]
# 下降パターン
minus = diff[0]

for i in range(len(diff) - 1):
    if diff[i + 1] + summary < 0:
        summary = 0
    else:
        if diff[i + 1] > 0:
            summary = summary + diff[i + 1]

if summary > 0:
    print(summary)

else:
    print(minus)

Submission status: Wrong Answer

Solution code:
# -*- coding=utf-8 -*-
price = [int(input()) for p in range(int(input()))]

min_ = price[0]
max_ = -100000000
for i in range(1, len(price)):
    if price[i] - min_ > max_:
        max_ = price[i] - min_

    if price[i] < min_:
        min_ = price[i]

print(max_)

Submission status: Wrong Answer

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

maxv = -200000000
minv = R[0]

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

print(maxv)

Submission status: Wrong Answer

Solution code:
import sys

count=int(input())-1
input_list=[ int(i) for i in sys.stdin.readlines() ]

first=0
second=1
max_price_diff=input_list[second]-input_list[first]

for i in input_list[first:count-1]:
    for j in input_list[second:count]:
        if j-i > max_price_diff:
            max_price_diff=j-i
    second=second+1

print(max_price_diff)

Submission status: Wrong Answer

Solution code:
import sys

count=int(input())-1
input_list=[ int(i) for i in sys.stdin.readlines() ]

first=0
second=1
max_price_diff=input_list[second]-input_list[first]

for i in input_list[first:count-1]:
    for j in input_list[second:count+1]:
        if j-i > max_price_diff:
            max_price_diff=j-i
    second=second+1

print(max_price_diff)

Submission status: Wrong Answer

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

n = int(input())
R = []
max_num = 0
min_num = 10 ** 9

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

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

print(max_num)

Submission status: Wrong Answer

Solution code:
import math

n=int(input())
t=int(input())
mint=t
t1=int(input())
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: Wrong Answer

Solution code:
import math

def main(argv):
    n = int(input())

    max = -2000000000
    min = int(input())

    for i in range(n):
        r = int(input())
        max = math.max(max, r-min)
        min = math.min(min, r)

    print(max)

Submission status: Wrong Answer

Solution code:
# f(j)-f(i)最大値を求める
input1 = [6,5,4,1,3,4,3]

max1 = input1[0]
min1 = input1[0]

for i in input1:
  if max1 < i:
    max1 = i
  if min1 > i:
    min1 = i
print("MAX:{} MIN:{}".format(max1,min1))

Submission status: Wrong Answer

Solution code:

if __name__ == "__main__":
    n = int(input())
    r0 = int(input())
    r1 = int(input())
    minv = r0 if r0 <= r1 else r1
    maxv = r1 - r0
    for i in range(2, n):
        r = int(input())
        if maxv >= (r-minv):
            maxv = r-minv
        if r <= minv:
            minv = r
    print(maxv)

Submission status: Wrong Answer

Solution code:

if __name__ == "__main__":
    n = int(input())
    r0 = int(input())
    r1 = int(input())
    minv = r0 if r0 <= r1 else r1
    maxv = r1 - r0
    for i in range(2, n):
        r = int(input())
        maxv = max(maxv, (r-minv))
        minv = min(minv, r)
    print(100)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    n = int(input())
    maxv = 10 ^ 9 * (-1)
    minv = int(input())

    for _ in range(1, n):
        temp = int(input())
        maxv = temp - minv if temp - minv > maxv else maxv
        minv = temp if temp < minv else minv

    print(maxv)

Submission status: Wrong Answer

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

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

print(maxv)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(input()) for i in range(1,n)]

max_mergin = -20000000000
min_value = a[0]
for abc in a:
    max_mergin = max(max_mergin, abc - min_value)
    min_value = min(min_value, abc)
    
print(max_mergin)

Submission status: Wrong Answer

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

max_mergin = -20000000000
min_value = a[0]
for abc in a:
    max_mergin = max(max_mergin, abc - min_value)
    min_value = min(min_value, abc)
    
print(max_mergin)

Submission status: Wrong Answer

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

max_mergin = -20000000000
min_value = a[1]
for abc in a:
    max_mergin = max(max_mergin, abc - min_value)
    min_value = min(min_value, abc)
    
print(max_mergin)

Submission status: Wrong Answer

Solution code:
n = int(input())
maxVal = -200000
minVal = int(input())
for i in range(1,n):
    x=int(input())
    dx = x-minVal
    if maxVal < dx:
        maxVal = dx
    if minVal > x:
        minVal = x
print(maxVal)

Submission status: Wrong Answer

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

b = a[1] - a[0]
for i in range(n):
    for j in range(i , n):
        if b < a[j] - a[i]:
            b = a[j] - a[i]

print(b)

Submission status: Wrong Answer

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

mini = a[0]
b = -100000

for i in a:
    if mini > i:
        mini = i
        print(mini)
    if b < i - mini:
        b = i - mini

Submission status: Wrong Answer

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

mini = a[0]
b = -100000

for i in a:
    if mini > i:
        mini = i
    if b < i - mini:
        b = i - mini

print(b)

Submission status: Wrong Answer

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

mini = a[0]
b = -100000
del a[0]
for i in a:
    if b < i - mini:
        b = i - mini
    if mini > i:
        mini = i
    print(mini,b)

Submission status: Wrong Answer

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

mini = a[0]
b = -100000
del a[0]
for i in a:
    if b < i - mini:
        b = i - mini
    if mini > i:
        mini = i

print(b)

Submission status: Wrong Answer

Solution code:
n = int(input())

min_rate = 10**9
max_prof = -1
for i in range(n):
    rate = int(input())
    prof = rate - min_rate
    if prof > max_prof:
        max_prof = prof
    if min_rate > rate:
        min_rate = rate

print(max_prof)

Submission status: Wrong Answer

Solution code:
n = int(input())

min_rate = 10**9
max_prof = -10**9
for i in range(n):
    rate = int(input())
    prof = rate - min_rate
    if prof > max_prof:
        max_prof = prof
    if min_rate > rate:
        min_rate = rate

print(max_prof)

Submission status: Wrong Answer

Solution code:
n = int(input())

min_rate = 10*15
max_prof = -10*15
for i in range(n):
    rate = int(input())
    prof = rate - min_rate
    if prof > max_prof:
        max_prof = prof
    if min_rate > rate:
        min_rate = rate

print(max_prof)

Submission status: Wrong Answer

Solution code:
import sys

if __name__ == '__main__':
    l = map(int, sys.stdin)
    del l[0]
    maxp = -999999
    minv = l[0]
    for i in range(1, len(l)):
        maxp = max(maxp, l[i] - minv)
        minv = min(minv, l[i])
    print maxp

Submission status: Wrong Answer

Solution code:
n = int(input())
buy = 1000000000
sell = 0
max_profit = -1000000000
for _ in range(n):
    r = int(input())
    if r < buy:
        sell = r
        max_profit = max(max_profit, sell - buy)
        buy = r
    else:
        sell = r
        max_profit = max(max_profit, sell - buy)

print(max_profit)

Submission status: Wrong Answer

Solution code:
n = int(input())
buy = 1000000000
sell = 0
max_profit = -1000000000
for _ in range(n):
    r = int(input())
    if r < buy:
        max_profit = max(max_profit, r - buy)
        sell = r
        buy = r
    else:
        sell = r
        max_profit = max(max_profit, sell - buy)

print(max_profit)

Submission status: Wrong Answer

Solution code:
n = int(input())
buy = 1000000000
sell = 0
max_profit = -1000000000
for _ in range(n):
    r = int(input())
    if r < buy:
        buy = r
        max_profit = max(max_profit, sell - buy)
        sell = r
    else:
        sell = r
        max_profit = max(max_profit, sell - buy)

print(max_profit)

Submission status: Wrong Answer

Solution code:
n = int(input())
buy = 1000000000
sell = 0
max_profit = -1000000000
for _ in range(n):
    r = int(input())
    if r < buy:
        max_profit = max(max_profit, r - buy)
        buy = r
    else:
        sell = r
        max_profit = max(max_profit, sell - buy)

print(max_profit)

Submission status: Wrong Answer

Solution code:
n = int(input())
buy = 1000000001
sell = 0
max_profit = -1000000001
for _ in range(n):
    r = int(input())
    if r < buy:
        max_profit = max(max_profit, r - buy)
        buy = r
    else:
        sell = r
        max_profit = max(max_profit, sell - buy)

print(max_profit)

Submission status: Wrong Answer

Solution code:
n = input()
n = int(n)
list = []

i = 0
while(i<n):
	x = input()
	x = int(x)
	list.append(x)
	i = i + 1

maxv = -20000000
minv = list[0]
i = 1
while(i<n):
	if(maxv >= list[i]-minv):
		maxv = maxv
	else:
		maxv = list[i]-minv
	
	if(minv <= list[i]):
		minv = minv
	else:
		minv = list[i]
	i = i + 1

print(maxv)

Submission status: Wrong Answer

Solution code:
n = input()
n = int(n)
list = []

i = 0
while(i<n):
	x = input()
	x = int(x)
	list.append(x)
	i = i + 1

maxv = -20000000
minv = list[0]
i = 1
while(i<n):
        maxv = max(maxv, list[i]-minv)
        minv = min(minv, list[i])
        i = i + 1
	
print(maxv)

Submission status: Wrong Answer

Solution code:
n = int(input())
min_price = int(input())
max_profit = int(input()) - min_price
for i in range(2, n):
	current = int(input())
	max_profit = max(max_profit, current - min_price)
	min_price = min(min_price, current)

print(max_profit)

Submission status: Wrong Answer

Solution code:
intMax = -100000000
inputData = int(input())
inputList = list()
for i in range(inputData):
    inputList.append(int(input()))

inputDataMax = intMax
inputDataMin = inputList[0]
for i in range(inputData):
    inputDataMax = max(inputDataMax,  inputList[i] - inputDataMin)
    inputDataMin = min(inputDataMin, inputList[i])

print(inputDataMax)

Submission status: Wrong Answer

Solution code:
intMax = -100000000
inputData = int(input())
inputList = list()
for i in range(inputData):
    inputList.append(int(input()))

inputDataMax = intMax
inputDataMin = inputList[0]
for i in range(inputData - 1):
    inputDataMax = max(inputDataMax,  inputList[i + 1] - inputDataMin)
    inputDataMin = min(inputDataMin, inputList[i + 1])

print(inputDataMax)

Submission status: Wrong Answer

Solution code:
N = input()
N = int(N)
l = [int(input()) for i in range(N)]
ma = -100
for i in range(0,len(l)-1):
    for j in range(i+1,len(l)):
        if(ma < l[j]-l[i]):
            ma = l[j] - l[i]
print(ma)

Submission status: Wrong Answer

Solution code:
import math

def max_price(price):
    res = 0
    for idx_j, j in enumerate(price):
        for i in range(idx_j):
            if j - price[i] > res:
                res = j - price[i]
    return res

def run():
    n = int(input())
    price = [int(input()) for _ in range(n)]
    print(max_price(price))

if __name__ == '__main__':
    run()

Submission status: Wrong Answer

Solution code:
import math

class MaxPrice(object):
    min_price = math.inf
    max_price = -math.inf

    def __init__(self):
        self.min_price = math.inf
        self.max_price = -math.inf

    @property
    def diff(self):
        return self.max_price - self.min_price

    def set_price(self, p):
        if self.max_price < p:
            self.max_price = p
        if p < self.min_price:
            self.min_price = p

def run():
    n = int(input())
    mp = MaxPrice()
    for i in range(n):
        p = int(input())
        mp.set_price(p)
    print(mp.diff)

if __name__ == '__main__':
    run()

Submission status: Wrong Answer

Solution code:
import math

class MaxPrice(object):
    
    def __init__(self):
        self.min_price = math.inf
        self.max_diff = -math.inf

    def set_price(self, p):
        if p < self.min_price:
            self.min_price = p
        if self.max_diff < p - self.min_price:
            self.max_diff = p - self.min_price

def run():
    n = int(input())
    mp = MaxPrice()
    for i in range(n):
        p = int(input())
        mp.set_price(p)
    print(mp.max_diff)

if __name__ == '__main__':
    run()

Submission status: Wrong Answer

Solution code:
import math

class MaxPrice(object):
    
    def __init__(self):
        self.min_price = math.inf
        self.max_price = -math.inf
        self.max_diff = -math.inf

    def set_price(self, p):
        if self.max_price < p:
            self.max_price = p
        if p < self.min_price:
            self.min_price = p

        if p != self.max_price and self.max_diff < p - self.max_price:
            self.max_diff = p - self.max_price
        if p != self.min_price and self.max_diff < p - self.min_price:
            self.max_diff = p - self.min_price
        print('diff -> ', self.max_diff)

def run():
    n = int(input())
    mp = MaxPrice()
    for i in range(n):
        p = int(input())
        mp.set_price(p)
    print(mp.max_diff)

if __name__ == '__main__':
    run()

Submission status: Wrong Answer

Solution code:
import math

class MaxPrice(object):
    
    def __init__(self):
        self.min_price = math.inf
        self.max_price = -math.inf
        self.max_diff = -math.inf

    def set_price(self, p):
        if self.max_price < p:
            self.max_price = p
        if p < self.min_price:
            self.min_price = p

        if p != self.max_price and self.max_diff < p - self.max_price:
            self.max_diff = p - self.max_price
        if p != self.min_price and self.max_diff < p - self.min_price:
            self.max_diff = p - self.min_price

def run():
    n = int(input())
    mp = MaxPrice()
    for i in range(n):
        p = int(input())
        mp.set_price(p)
    print(mp.max_diff)

if __name__ == '__main__':
    run()

Submission status: Wrong Answer

Solution code:
# Maximum Profit

n = int(input())

maximumProfit = - 10 ** 9
minimum = 10 ** 9

i = 0
while i < n:
    a = int(input())
    maximumProfit = max(a - minimum, maximumProfit)
    minimum = min(a, minimum)
    i += 1

print(maximumProfit)

Submission status: Wrong Answer

Solution code:
n = int(input())
rlist = []
for i in range(n):
    r = int(input())
    rlist.append(r)
mlist = [rlist[1] - rlist[0]]
for i in range(n):
    for k in range(n):
        if(i>k):
            if(rlist[i] - rlist[k] > mlist[-1]):
                mlist.append(rlist[i] - rlist[k])
            else:
                break
        else: 
            break
print(mlist[-1])

Submission status: Wrong Answer

Solution code:
import sys

a = []
for line in sys.stdin:
    a.append(int(line))
b = a

del a[0]
del a[len(a)-1]

del b[0]
del b[0]
print(max(b)-min(a))

Submission status: Wrong Answer

Solution code:
import sys

a = []
for line in sys.stdin:
    a.append(int(line))

b = a
del a[0]
del a[len(a)-1]
del b[0]
del b[0]
print(max(b)-min(a))

Submission status: Wrong Answer

Solution code:
import sys

a = []
for line in sys.stdin:
    a.append(int(line))

b = a
del a[0]
del a[len(a)-1]
del b[0]
del b[0]

list = []
for i in range(len(a)-1):
    for j in range(len(a)-1):
        if j > i:
            sub = b[j]-a[i]
            list.append(sub)
print(max (list))

Submission status: Wrong Answer

Solution code:
import sys

a = []
for line in sys.stdin:
    a.append(int(line))

b = a
del a[0]
del a[len(a)-1]
del b[0]
del b[0]

list = []
for i in range(len(a)-1):
    for j in range(len(a)-1):
        if j >= i:
            sub = b[j]-a[i]
            list.append(sub)
print(max (list))

Submission status: Wrong Answer

Solution code:
import sys

a = []
for line in sys.stdin:
    a.append(int(line))

b = a
del a[0]
del a[len(a)-1]
del b[0]
del b[0]

list = []
for i in range(len(a)-1):
    for j in range(len(b)-1):
        if j >= i:
            sub = b[j]-a[i]
            list.append(sub)
print(max (list))

Submission status: Wrong Answer

Solution code:
import sys

a = []
b = []
for line in sys.stdin:
    a.append(int(line))
    b.append(int(line))

del a[0]
del a[len(a)-1]
del b[0]
del b[0]

list = []
for i in range(len(a)-1):
    for j in range(len(b)-1):
        if j >= i:
            sub = b[j]-a[i]
            list.append(sub)
print(max (list))

Submission status: Wrong Answer

Solution code:
import sys

a = []
b = []
for line in sys.stdin:
    a.append(int(line))
    b.append(int(line))

del a[0]
del a[len(a)-1]
del b[0]
del b[0]

sub = -100000000
for i in range(len(a)):
    for j in range(len(b)):
        if j >= i:
            if sub <= b[j]-a[i]:
                sub = b[j]-a[i]
print(sub)

Submission status: Wrong Answer

Solution code:
import sys

a = []
b = []
for line in sys.stdin:
    a.append(int(line))
    b.append(int(line))

del a[0]
del a[len(a)-1]
del b[0]
del b[0]

sub = -100000000
for i in range(len(a)):
    for j in range(len(b)):
        if j >= i:
            if sub <= b[j]-a[i]:
                sub = b[j]-a[i]
print(sub)

Submission status: Wrong Answer

Solution code:
import sys

a = []
b = []
for line in sys.stdin:
    a.append(int(line))
    b.append(int(line))

del a[0]
del a[len(a)-1]
del b[0]
del b[0]

maxv = -100000000
minv = a[0]
for i in range(len(a)):
    maxv = max(maxv,b[i]-minv)
    minv = min(minv,b[i])
print(maxv)

Submission status: Wrong Answer

Solution code:
import math
 
n = int(input())
tmp = int(input())
tmpmin = tmp
t1 = int(input())
if t1 < tmp: tmpmin = t1
tmpmax = t1 - tmp
ans = 0
 
 
for i in range(2,n):
    tmp = int(input())
  
    if tmp - tmpmin > ans: ans = tmp - tmpmin
    if tmp < tmpmin: tmpmin = tmp
     
print(int(ans))

Submission status: Wrong Answer

Solution code:
minv = -1000000000
maxv = 1000000000

for _ in range(int(input())) :
    num	= int(input())
    maxv = max(maxv,num	- minv)
    minv = min(minv,num)
print(maxv)

Submission status: Wrong Answer

Solution code:
maxv = -1000000000
minv = 1000000000

for _ in range(int(input())) :
    num = int(input())
    maxv = max(maxv,num - minv)
    minv = min(minv,num)
print(maxv)

Submission status: Wrong Answer

Solution code:
n=input()
l=[input() for _ in range(n)]
chk,ans=l[0],0
for i in range(1,n):
    chk=min(chk,l[i-1])
    if l[i]-chk>ans:
        ans=l[i]-chk
print ans

Submission status: Wrong Answer

Solution code:
n=input()
l=[input() for _ in range(n)]
mi=l.index(min(l[:-2]))
ma=l.index(max(l[1:]))
print max(max(l[1:])-min(l[:ma]),max(l[mi:])-min(l))

Submission status: Wrong Answer

Solution code:
mini = float("inf")
def f(n):
    global mini
    mini = min(mini, n)
    return n - mini
print max(f(input()) for _ in xrange(input()))

Submission status: Wrong Answer

Solution code:
a = []
n = int(input())
for i in range(n):
    a.append(int(input()))
i = min(range(n), key=lambda x:a[x])
print(max(a[i:]) - a[i])

Submission status: Wrong Answer

Solution code:
maxv = -10**9
minv = 10**9
n = int(input())
for i in range(n):
    x = int(input())
    if x - minv > maxv:
        maxv = x - minv
    if x < minv:
        minv = x
print(maxv)

Submission status: Wrong Answer

Solution code:
maxv = -10**9
minv = 10**9
n = int(input())
for i in range(n):
    x = int(input())
    if x < minv:
        minv = x
    if x - minv > maxv:
        maxv = x - minv
print(maxv)

Submission status: Time Limit Exceeded

Solution code:
numberOfInput=int(input())
numberForStock=[]
index=0
while index<numberOfInput:
    inputNumber=int(input())
    numberForStock.append(inputNumber)
    index+=1

numberForReturn=-10**9
for indexForMax in range(1,numberOfInput):
    for indexForMin in range(0,indexForMax):
        if numberForReturn<numberForStock[indexForMax]-numberForStock[indexForMin]:
            numberForReturn=numberForStock[indexForMax]-numberForStock[indexForMin]
            
        
print(numberForReturn)

Submission status: Time Limit Exceeded

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

max_diff = min(r) - max(r) - 1

for i in range(N) :
    for j in range(i + 1, N) :
        max_diff = max(max_diff, r[j] - r[i])
        
print(max_diff)

Submission status: Time Limit Exceeded

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

cur_min = max(r) + 1
max_diff = min(r) - max(r) - 1
search_from_idx = 1

for i in range(N) :
    if r[i] >= cur_min :
        continue
        
    if search_from_idx <= i :
        search_from_idx = i + 1
        
    for j in range(search_from_idx, N) :
        if max_diff < r[j] - r[i] :
            max_diff = r[j] - r[i]
            search_from_idx = j

    cur_min = min(r[i], cur_min)
        
print(max_diff)

Submission status: Time Limit Exceeded

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

cur_max_diff = min(r) - max(r)
cur_min_idx = -1

for i in range(n) :
    
    if i == 0 :
        for j in range(1, n) :
            if r[j] - r[i] > cur_max_diff :
                cur_max_diff = r[j] - r[i]
                cur_min_idx = j
                
    elif i >= cur_min_idx :
        for j in range(i + 1, n) :
            if r[j] - r[i] > cur_max_diff :
                cur_max_diff = r[j] - r[i]
                cur_min_idx = j
    else :
        cur_max_diff = max(cur_max_diff, r[cur_min_idx] - r[i])
        
print(cur_max_diff)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ls = [int(input()) for _ in range(n)]
ls.reverse()

result = []
for i in range(n-1):
    result.append(ls[i] - min(ls[i+1:]))

print(max(result))

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    numlist = []
    for _ in range(n):
        numlist.append(int(input()))

    maxprofit = numlist[1] - numlist[0]
    for i in range(n-1):
        for j in range(i+1, n):
            if numlist[j] - numlist[i] > maxprofit:
                maxprofit = numlist[j] - numlist[i]
    print(maxprofit)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    numlist = []
    for _ in range(n):
        numlist.append(int(input()))

    maxprofit = numlist[1] - numlist[0]
    for i in range(n-1):
        if maxprofit < max(numlist[i+1:n]) - numlist[i]:
            maxprofit = max(numlist[i+1:n]) - numlist[i]
    print(maxprofit)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# とても時間がかかる

def main():
    n = int(input())
    numlist = []
    for _ in range(n):
        numlist.append(int(input()))

    maxprofit = []
    for i in range(n-1):
        maxprofit.append(max(numlist[i+1:n]) - min(numlist[0:i+1]))
    print(max(maxprofit))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# とても時間がかかる

def main():
    n = int(input())
    numlist = []
    for _ in range(n):
        numlist.append(int(input()))

    maxprofit = numlist[1] - numlist[0]
    for i in range(n-1):
        x = max(numlist[i+1:n])
        y = min(numlist[0:i+1])
        if maxprofit < x - y:
            maxprofit = x - y
    print(maxprofit)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
R=[0 for i in range(n)]
for i in range(n):
    R[i]=int(input())
max=R[1]-R[0]
for i in range(n-1):
    for j in range(i+1,n):
        x=R[j]-R[i]
        if max<x:
            max=x
print(max)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
R=[0 for i in range(n)]
for i in range(n):
    R[i]=int(input())
max=-100000000000
for i in range(n-1):
    for j in range(i+1,n):
        x=R[j]-R[i]
        if max<x:
            max=x
print(max)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[0]*n
for i in range(0,n):
    a[i]=int(input())
max=a[1]-a[0]
for i in range(0,n):
    for j in range(i+1,n):
        if max<a[j]-a[i]:
            max=a[j]-a[i]
print(max)

Submission status: Time Limit Exceeded

Solution code:
n = input()
l = list()

max_profit = None

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



for i in range(0,len(l)):
	for j in range(i+1,len(l)):
		if max_profit == None:
			max_profit = l[j] - l[i]
		elif max_profit < l[j] - l[i]:
			max_profit = l[j] - l[i]


print(max_profit)

Submission status: Time Limit Exceeded

Solution code:
n = input()
l = list()

max_profit = None

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



for i in range(0,len(l)):
	for j in range(i+1,len(l)):
		tmp_max = max(l[j:])
		profit = l[j] - l[i]
		if max_profit < profit:
			max_profit = profit

print(max_profit)

Submission status: Time Limit Exceeded

Solution code:
n = input()
l = list()

max_profit = None
tmp_i = 1000000001
for i in range(0,n):
	l.append(input())



for i in range(0,len(l)):
	if tmp_i <= l[i]:
		continue

	for j in range(i+1,len(l)):
		tmp_max = max(l[j:])
		profit = l[j] - l[i]
		if max_profit < profit:
			max_profit = profit

	tmp_i = l[i]

print(max_profit)