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: Time Limit Exceeded

Solution code:
# coding: UTF-8
n = int(raw_input())
value_list = []
diff_indx1 = 0
diff_indx2 = 0
for i in range(n):
    value_list.append(int(raw_input()))
    if i == 1:
        diff = value_list[1] - value_list[0]
        diff_indx1 = 1
    if value_list[i] >= value_list[diff_indx1]:
        for j in range(i):
            diff2 = value_list[i] - value_list[j]
            if diff <= diff2:
                diff = diff2
                diff_indx1 = i
                diff_indx2 = j
                #print("{}:{} - {} = {}").format(diff_indx1,value_list[i],value_list[j],diff)
    elif value_list[diff_indx2] > value_list[i]:
        diff_indx2 = i
        diff_indx1 = i
print diff

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
datas = [int(input()) for _ in range(N)]
diff = max(datas[1:]) - datas[0]

for i in range(1,N-1):
    new_diff = max(datas[i+1:]) - datas[i]
    if diff < new_diff:
        diff = new_diff

print(diff)

Submission status: Time Limit Exceeded

Solution code:
n = int(raw_input())
nums = [int(raw_input()) for i in range(n)]

maxv = nums[1] - nums[0]
for j in range(1, n):
    for i in range(j):
        maxv = max(maxv, nums[j]-nums[i])

print maxv

Submission status: Time Limit Exceeded

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

r_temp_min = r[0]
ans = r[1]-r[0]

for r_i in r[1:]:
    if ans < (r_i - r_temp_min):
        ans = r_i - r_temp_min

for i,r_i in enumerate(r):
    if r_temp_min <= r_i:
        continue
    r_temp_min = r_i

    for r_j in r[(i+1):]:
        if ans < (r_j - r_i):
            ans = r_j - r_i

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def maximum_profit(n):
    maxv = min(n) - max(n)
    for i in range(len(n)-1):
        m = max(n[i+1:])
        if maxv < m - n[i]:
            maxv = m - n[i]
    return maxv

if __name__ == '__main__':
    n = []
    for _ in range(int(input())):
        n.append(int(input()))
    print(maximum_profit(n))

Submission status: Time Limit Exceeded

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

max_diff = nums[1] - nums[0]
for i in range(len(nums)):
    for j in range(i+1, len(nums)):
        diff = nums[j] - nums[i]
        if max_diff >= diff:
            continue
        else:
            max_diff = diff

print(max_diff)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque


def main():
    d = deque()
    for _ in range(int(input())):
        d.append(int(input()))
    
    result = min(d) - max(d)

    while d:
        c = d.popleft()
        if not d:
            break

        if max(d) - c > result:
            result = max(d) - c
    
    print(result)



if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*
import sys
if False:
#if True:
    fh=open('ALDS1_1_D1.txt','r')
else:
    fh=sys.stdin
input=fh.readline

def main():
    n = int(input())
    a=[]
    for _ in range(n):
        a.append(int(input()))
    #print('a=',a)
    pmax=a[1]-a[0]
    for k in range(0, n-1):
        p=max(a[k+1:])-a[k] 
        if p > pmax:
            pmax=p

    print(pmax)
    
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

num_list = []
diff = -sys.maxsize -1
for i in range(int(input())):
    num_list.append(int(input()))

for (idx, Rt) in enumerate(num_list):
    if(idx+1 == len(num_list)-1):
        tmp = num_list[idx+1] - Rt
        if (tmp > diff):
            diff = tmp
    else:
        for Rj in num_list[idx+1:]:
            tmp = Rj - Rt
            if(tmp > diff):
                diff = tmp

print(diff)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
import math




if __name__ == '__main__' :
    n = int(input())
    R = [int(input()) for i in range(n)]
    tmp = [max(R[i+1::])  - R[i] for i in range(n-1)]
    print(max(tmp))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
prices = [int(input()) for i in range(n)]
ans = 1 - (10 ** 9)
for x in range(n-1):
    for y in range(x+1, n):
        ans = max(ans, prices[y] - prices[x])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def set_values():
	values = []
	for i in range(int(input())):
		values.append(int(input()))
	return values

def check_all(values):
	max_value = min(values) - max(values)
	for i in range(len(values)-1):
		count = i + 1
		max_value = get_max_value(i, len(values), count, max_value)
	return max_value

def get_max_value(now_index, length, count, max_value):

	while count < length:
		if max_value < (values[count] - values[now_index]):
			max_value = (values[count] - values[now_index])
		count += 1
	return max_value

values = set_values()
max_value = check_all(values)
print(max_value)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
ans = a[1]-a[0]
for i in range(n-1):
  for j in range(i+1,n):
    if a[j] - a[i] > ans:
      ans = a[j] - a[i]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
ans = a[1]-a[0]
for i in range(n-1):
  k = max(a[i+1:]) - a[i]
  if k > ans:
      ans =  k
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
nowmin = a[0]
ans = a[1]-a[0]
for i in range(n-1):
  if a[i] <= nowmin:
    k = max(a[i+1:]) - a[i]
    if k > ans:
      ans =  k
      nowmin = a[i]
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
nowmin = a[0] + 1
ans = a[1]-a[0]
for i in range(n-1):
  if a[i] < nowmin:
    k = max(a[i+1:]) - a[i]
    if k > ans:
      ans =  k
      nowmin = a[i]
    
print(ans)

Submission status: Time Limit Exceeded

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

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

max_dist = -10e10

for i in range(N-1):
	for j in range(i + 1, N):
		if a[j] - a[i] > max_dist:
			max_dist = a[j] - a[i]

print(max_dist)

Submission status: Time Limit Exceeded

Solution code:
import sys

values = [int(input()) for i in range(int(input()))]

maxv = - sys.maxsize - 1

for c, i in enumerate(values):
    for j in values[c + 1:]:
        val = j - i
        if maxv < val:
            maxv = val

print(maxv)

Submission status: Time Limit Exceeded

Solution code:
#
# P.48 O(n^2)となる単純な回答（比較用）
#
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_D
#
import sys

values = [int(input()) for i in range(int(input()))]

maxv = - sys.maxsize - 1

for c, i in enumerate(values):
    for j in values[c + 1:]:
        maxv = max(maxv, j - i)

print(maxv)

Submission status: Time Limit Exceeded

Solution code:
import sys

values = [int(input()) for i in range(int(input()))]

maxv = - sys.maxsize - 1

for c, i in enumerate(values):
    for j in values[c + 1:]:
        maxv = max(maxv, j - i)

print(maxv)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())

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

max_dif=nums[1]-nums[0]
for i in range(n):
    for j in range(i+1,n):
        dif=nums[j]-nums[i]
        if max_dif<dif:
            max_dif=dif
print(max_dif)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())

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

max_dif=nums[1]-nums[0]
for i in range(n):
    for j in range(i+1,n):
        dif=nums[j]-nums[i]
        if max_dif<dif:
            max_dif=dif
print(max_dif)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())

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

max_dif=nums[1]-nums[0]
for i in range(n):
    for j in range(i+1,n):
        dif=nums[j]-nums[i]
        if max_dif<dif:
            max_dif=dif
print(max_dif)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
x = []
for i in range(n):
    x.append(int(input()))
m = float("inf") * (-1)
for i in range(n-1):
    for j in range(i+1,n):
        if m < (x[j] - x[i]):
            m = x[j] - x[i]
print(m)

Submission status: Time Limit Exceeded

Solution code:
import sys

values = [int(input()) for i in range(int(input()))]

maxv = - sys.maxsize - 1

for c, i in enumerate(values):
    for j in values[c + 1:]:
        maxv = max(maxv, j - i)

print(maxv)

Submission status: Time Limit Exceeded

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

maxv = values[1] - values[0]

for c, i in enumerate(values):
    for j in values[c + 1:]:
        maxv = max(maxv, j - i)

print(maxv)

Submission status: Time Limit Exceeded

Solution code:
#16D8101012J 伊藤惇 dj Python3

def Maximum_Profit(n,A):
    Max=(min(A)-max(A))
    for i in range(n-1):
        for j in range(i+1,n):
            if Max<A[j]-A[i]:
                Max=A[j]-A[i]
    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: Time Limit Exceeded

Solution code:
#16D8101012J 伊藤惇 dj Python3

def Maximum_Profit(n,A):
    Max=(min(A)-max(A))
    for i in range(n-1):
        if Max<(max(A[i+1:])-A[i]):
            Max=(max(A[i+1:])-A[i])
    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: Time Limit Exceeded

Solution code:
#16D8101012J 伊藤惇 dj Python3

def Maximum_Profit(n,A):
    Max=(min(A)-max(A))
    for i in range(n-1):
        tmp=(max(A[i+1:])-A[i])
        if Max<tmp:
            Max=tmp
    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: Time Limit Exceeded

Solution code:
#16D8101012J 伊藤惇 dj Python3
import sys

def Maximum_Profit(n,A):
    Max=-sys.maxsize
    for i in range(n-1):
        tmp=(max(A[i+1:])-A[i])
        if Max<tmp:
            Max=tmp
    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: Time Limit Exceeded

Solution code:


n=int(input())

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

max=list[1]-list[0]


for i in range(n-1,-1,-1):
	for j in range(i):
		x=list[i]-list[j]
		if x>max:
			max=x

		
print(max)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
intMax = -100000000

inputData = int(input())
inputList = list()
count = 0
while count < inputData:
    inputList.append(int(input()))
    count = count + 1

inputDataMax = intMax
inputDataMin = inputList[0]
count2 = 1
while count2 < inputData:
    inputDataMax = max(inputDataMax,  inputList[count2] - inputDataMin)
    inputMin = min(inputDataMin, inputList[count2])

print(inputDataMax)

Submission status: Time Limit Exceeded

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):
        tmp = a[i]-a[j]
        if max<tmp:
            max = tmp

print(max)

Submission status: Time Limit Exceeded

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-1):
    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: Time Limit Exceeded

Solution code:
#! python3
# maximum_profit.py

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

max_val = R[1] - R[0]
for i in range(n-1):
    for j in range(i+1, n):
        val = R[j] - R[i]
        if max_val < val:
            max_val = val

print(max_val)

Submission status: Time Limit Exceeded

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

max_value = -10**9
for i in range(n):
    for j in range(i+1,n):
        if r[j] - r[i] > max_value:
            max_value = r[j] - r[i]
print(max_value)

Submission status: Time Limit Exceeded

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

max_value = -10**9
for i in range(n):
    for j in range(i+1,n):
        rji = r[j] - r[i]
        if rji  > max_value:
            max_value = rji
print(max_value)

Submission status: Time Limit Exceeded

Solution code:
#! python3
# maximum_profit.py

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

maximum_profit = R[-1]-R[-2]
for i in range(n-2):
    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: Time Limit Exceeded

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
    else:
        min_i = R[i]
    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: Time Limit Exceeded

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]:
    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: Time Limit Exceeded

Solution code:
def maximum_profit(n):
    max_profit = min(n) - max(n)
    for i in range(1, len(n)):
        x = max(n[i:]) - n[i-1]
        if max_profit < x:
            max_profit = x
    return max_profit

if __name__ == '__main__':
    n = int(input())
    numbers = [int(input()) for i in range(0, n)]
    print(maximum_profit(numbers))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
max =a[1]-a[0]
for i in range(1,len(a)):
    for j in range(i):
        b = a[i] - a[j]
        if b > max:
           max = b
print(max)

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8

n = int(input())

pri_list = [int(input()) for i in range(n)]
gap_list = []
for i in range(n-1):
    gap = max(pri_list[i+1:]) - pri_list[i]
    gap_list.append(gap)
max_ben = max(gap_list)

print(max_ben)

Submission status: Time Limit Exceeded

Solution code:
def maximum_profit(rs):
    ans = rs[1] - rs[0]
    for i in range(n):
        for j in range(i + 1, n):
            if ans < rs[j] - rs[i]:
                ans = rs[j] - rs[i]
    return ans


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

print(maximum_profit(rs))

Submission status: Time Limit Exceeded

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+1 , n):
        if b < a[j] - a[i]:
            b = a[j] - a[i]

print(b)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
R = []
max = -10**9
for i in range(n):
    R.append(int(input()))
for i in range(n-1):
    for j in range(i+1, n):
        if R[j] - R[i] > max:
            max = R[j] - R[i]
print(max)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math

def max_price(price):
    res = -math.inf
    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: Time Limit Exceeded

Solution code:
n = int(input())
rlist = []
for i in range(n):
    r = int(input())
    rlist.append(r)
mlist = []
for i in range(n):
    j = i-1
    while (j >= 0):
        m = rlist[i] - rlist[j]
        mlist.append(m)
        j -= 1
mlist.sort()
print(mlist[-1])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
rlist = []
for i in range(n):
    r = int(input())
    rlist.append(r)
mlist = []
for i in range(n):
    if(i != 0):
        m = rlist[i] - min(rlist[:i])
        mlist.append(m)
mlist.sort()
print(mlist[-1])

Submission status: Time Limit Exceeded

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(1,n):
    m = rlist[i] - min(rlist[:i])
    if(m > mlist[-1]):
        mlist.append(m)
        
print(mlist[-1])

Submission status: Time Limit Exceeded

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)):
    for j in range(len(b)):
        if j >= i:
            sub = b[j]-a[i]
            list.append(sub)
print(max (list))

Submission status: Time Limit Exceeded

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 = -10000000000000
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: Time Limit Exceeded

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 = -100000000000
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: Time Limit Exceeded

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 = -100000000000
for i in range(len(a)):
    for i in range(len(a)):
        for j in range(len(a)-i):
            if sub <= b[i+j]-a[i]:
                sub = b[i+j]-a[i]
print(sub)

Submission status: Time Limit Exceeded

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]

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

Submission status: Time Limit Exceeded

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 = -1000000000
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: Time Limit Exceeded

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 = -1000000000
for i in range(len(a)):
    for j in range(len(b)):
        if j >= i:
            sub = max(sub,b[j]-a[i])
print(sub)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
a = []
n = int(input())
for i in range(n):
    a.append(int(input()))
print(max(a[j] - a[i] for i in range(n) for j in range(i + 1, n)))

Submission status: Time Limit Exceeded

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

Submission status: Memory Limit Exceeded

Solution code:
price_list = []
num_list = []
t = raw_input()
for i in range(int(t)):
    price_list.append(int(input()))

for i in range(len(price_list)):
    for j in range(i):
        num_list.append(price_list[i] - price_list[j])
print max(num_list)

Submission status: Memory Limit Exceeded

Solution code:
def main():
	n=input()
	List_1=[]
	List_2=[]
	for i in range(n):
		List_1.append(input())
		for j in range(i-1,-1,-1):
				List_2.append(List_1[i]-List_1[j])
	List_2.sort()
	print(List_2[len(List_2)-1])
	
if __name__=='__main__':
	main()

Submission status: Memory Limit Exceeded

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

print(max([R[j] - R[i] for i in range(len(R)) for j in range(len(R)) if j > i]))

Submission status: Memory Limit Exceeded

Solution code:
num = []
x = input()
for i in xrange(x):
    num.append(input())

ans = []
num = num[::-1]
for i in xrange(len(num)):
    for j in xrange(len(num)-(i+1)):
        ans.append(num[i]-num[j+i+1])
print max(ans)

Submission status: Memory Limit Exceeded

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

interest = []
for i in range(n):
    for j in range(i+1,n):
        interest.append(m[j]-m[i])
print(max(interest))

Submission status: Memory Limit Exceeded

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

candidate = []
for i, v in enumerate(stack):
    for j in stack[:i]:
        candidate.append(v - j)

print(max(candidate))

Submission status: Memory Limit Exceeded

Solution code:
from sys import stdin
n = int(input())
r=[int(input()) for i in range(n)]
rv = r[::-1][:-1]
print(max([r_j - r_i for j,r_j in enumerate(rv) for r_i in r[:-(j+1)]]))

Submission status: Memory Limit Exceeded

Solution code:
n = int(input())
R = [int(input()) for i in range(n)]
profit=[]
for i in range(n):
    for j in range(i+1,n):
        profit.append(R[j]-R[i])
print(max(profit))

Submission status: Memory Limit Exceeded

Solution code:
import sys

num = int(input())
input_line = sys.stdin.readlines()
inputnum = [int(x.strip()) for x in input_line]

diff = []
for j in range(num):
    for i in range(j):
        diff.append(inputnum[j] - inputnum[i])
if len(diff)==1:
    print(max(diff))
else:
    print(max(*diff))

Submission status: Memory Limit Exceeded

Solution code:
n = int(input())

l = [0] * n
for i in range(n):
    l[i] = int(input())

x = []
for j in range(1, n):
    for i in range(j):
        x.append(l[j] - l[i])

print(max(x))

Submission status: Memory Limit Exceeded

Solution code:
n = int(input())

l = [0] * n
for i in range(n):
    l[i] = int(input())

x = [l[j] - l[i] for j in range(1, n) for i in range(j)]

print(max(x))

Submission status: Memory Limit Exceeded

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

P = []
for i in range(n-1):
    for j in range(i+1, n):
        P.append(R[j]-R[i])

P.sort()
print(P[-1])

Submission status: Memory Limit Exceeded

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

for i in range(n):
    for j in range(i+1,n):
      rate.append(int(Rt[j]) - int(Rt[i]))

print(max(rate))

Submission status: Memory Limit Exceeded

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

ans = []
while data:
	x = data.pop(0)
	table = [d - x for d in data]
	ans += table
print(max(ans))

Submission status: Memory Limit Exceeded

Solution code:
x = int(input())
l=[]
for i in range(x):
    l.append(int(input()))
ans = []
for i, v1 in enumerate(l):
    for j, v2 in enumerate(l):
        if j > i:
            ans.append(v2-v1)
print(max(ans))

Submission status: Memory Limit Exceeded

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

candidate = []    
for i in range(N):
    for j in range(i+1, N):
        candidate.append(List[j]-List[i])

print(max(candidate))

Submission status: Memory Limit Exceeded

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

a=[]
for i in range(n):
	for j in range(i+1,n):
		a.append(Rt[j]-Rt[i])
		
print(max(a))

Submission status: Memory Limit Exceeded

Solution code:
n = int(input())
nums = []
ns = []

for v in range(n):
    num = int(input())
    nums.append(num)

for p in range(n):
    a = nums[p]
    for q in range(p+1,n):
        b = nums[q]
        ns.append(b-a)
        
print(max(ns))

Submission status: Memory Limit Exceeded

Solution code:
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
b = []
for i in range(1,len(a)):
    for j in range(i):
        b.append(a[i]-a[j])
print(max(b))

Submission status: Accepted

Solution code:
n = int(input())

# initial observation
cur_min = int(input())
max_diff = -1 * (10**9) - 1

for i in range(n - 1) :
    num = int(input())
    
    max_diff = max(max_diff, num - cur_min)
    
    if num < cur_min :
        cur_min = num
    
print(max_diff)

Submission status: Accepted

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

result = []
biggest = 0
for i in range(n-1):
    last = ls.pop()
    if last > biggest:
        biggest = last
        result.append(last - min(ls))
print(max(result))

Submission status: Accepted

Solution code:
n = int(input())
maxt = -float("inf")
for i in range(n):
    t = int(input())
    if i == 0:
        mint = t
    else:
        if t - mint > maxt:
            maxt = t - mint
        if t < mint:
            mint = t
print(maxt)

Submission status: Accepted

Solution code:
n=int(input())
minv=int(input())
maxv=-1*float('inf')
for i in range(n-1):
    r=int(input())
    maxv=max(maxv,r-minv)
    minv=min(minv,r)
print(maxv)

Submission status: Accepted

Solution code:
def max_profit(A, n):
    minv = A[0]
    for j in range(1, n):
        if j == 1:
            maxv = A[j] - A[j-1]
        if maxv < A[j] - minv:
            maxv = A[j] - minv
        if minv > A[j]:
            minv = A[j]
    print(maxv)

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

max_profit(A, n)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    t0 = int(input())
    t1 = int(input())
    tmpmin = t0
    tmpmax = t1 - t0
    tmpmin = min(t0, t1)

    for _ in range(2,n):
        t = int(input())
        if t - tmpmin > tmpmax:
            tmpmax = t - tmpmin 
        if t < tmpmin:
            tmpmin = t
    print(tmpmax)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    t0 = int(input())
    t1 = int(input())

    tmpmax = t1 - t0
    tmpmin = min(t0, t1)

    for _ in range(2,n):
        t = int(input())
        if t - tmpmin > tmpmax:
            tmpmax = t - tmpmin 
        if t < tmpmin:
            tmpmin = t
    print(tmpmax)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#! /usr/local/bin/python3
# coding: utf-8

n = int(input())

min_r = int(input())
max_margin = -1000000001

for i in range(n - 1):
    r = int(input())
    max_margin = max(r - min_r, max_margin)
    min_r = min(r, min_r)

print(max_margin)

Submission status: Accepted

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

max_j = n - 1
max_diff = r[max_j] - r[max_j - 1]

for i in range(n-3, -1, -1):
    if r[i+1] > r[max_j]:
        max_j = i + 1
    tmp_diff = r[max_j] - r[i]
    if max_diff < tmp_diff:
        max_diff = tmp_diff

print(max_diff)

Submission status: Accepted

Solution code:
inputs = []
while True:
    try:
        inputs.append(int(input()))
    except(EOFError):
        break

inputs.pop(0)

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

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

print(maxv)

Submission status: Accepted

Solution code:
# coding: utf-8

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

MIN = R[0]
MAXdiff = R[1]-R[0]

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

print(MAXdiff)

Submission status: Accepted

Solution code:
N = int(input())
R = [int(input()) for _ in range(N)]
maxv = -2000000000
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())
R=[int(input()) for i in range(n)]
mini=10**10
maxi=-10**10
for r in R:
    maxi=max([maxi,r-mini])
    mini=min([mini,r])
print(maxi)

Submission status: Accepted

Solution code:
cnt = 0
for i in range(int(input())):
    c_num = int(input())
    if cnt == 0:
        r_min = c_num
    elif cnt == 1:
        p_max = c_num - r_min
        if c_num < r_min:
            r_min = c_num
    else:
        if p_max < c_num - r_min:
            p_max = c_num - r_min
        if c_num < r_min:
            r_min = c_num
    cnt += 1
print(p_max)

Submission status: Accepted

Solution code:
N = int(input())

price_list = [int(input()) for _ in range(N)]

purchase_price = price_list[0]
profit = price_list[1] - purchase_price
for price in price_list[1:]:
    if profit < price - purchase_price:
        profit = price - purchase_price
    if price < purchase_price:
        purchase_price = price

print(profit)

Submission status: Accepted

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

purchase_price = price_list[0]
profit = price_list[1] - purchase_price
for price in price_list[1:]:
    profit = max(profit, (price-purchase_price))
    purchase_price = min(price, purchase_price)

print(profit)

Submission status: Accepted

Solution code:
N = int(input())

purchase_price = int(input())
profit = -2000000000
for _ in range(N-1):
    price = int(input())
    profit = max(profit, (price-purchase_price))
    purchase_price = min(price, purchase_price)

print(profit)

Submission status: Accepted

Solution code:
n=int(raw_input().strip())
lst=[]
minval=0x3f3f3f3f
ans=-0x3f3f3f3f
for i in xrange(n):
    val=int(raw_input().strip())
    if(i>=1):
        #print val,minval
        ans=max(ans,val-minval)
    minval = min(minval, val)
print ans