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:
n = int(input())
ls = [int(input()) for _ in range(n)]

p = []
for i, x in enumerate(ls):
    if i+1 != len(ls):
        p.append(max(ls[i+1:])-x)

print(max(p))

Submission status: Time Limit Exceeded

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

pp = [max(ls[i:])-x for i, x in enumerate(ls, 1) if i != len(ls)]

print(max(pp))

Submission status: Time Limit Exceeded

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

#pp = [max(ls[i:])-x for i, x in enumerate(ls, 1) if i != len(ls)]

p = min(ls) - max(ls)

for i, x in enumerate(ls, 1):
    if i == len(ls):
        break
    if max(ls[i:]) - x > p:
        p = max(ls[i:]) - x

print(p)

Submission status: Time Limit Exceeded

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

p = min(ls) - max(ls)

for i, x in enumerate(ls, 1):
    if i == len(ls):
        break
    v = max(ls[i:]) - x
    if v > p:
        p = v
print(p)

Submission status: Time Limit Exceeded

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

print(max_s)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = []
for i in range(n):
    s.append(int(input()))
max_s = -10**9
for i in range(n-1):
    R_i = s[i]
    s[i] = 0
    R_j = max(s)
    R = R_j - R_i
    if R > max_s:
        max_s = R

print(max_s)

Submission status: Time Limit Exceeded

Solution code:
r = []

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

maxv = r[1] - r[0]

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

print(maxv)

Submission status: Time Limit Exceeded

Solution code:
import math

n = int(input())
r_t = [int(input().strip()) for i in range(n)]

r_i = r_t[0]
r_i_index = 0
diff = -math.inf
for _ in range(1, n):
    r_j = max(r_t[r_i_index+1:])

    tmp_diff = r_j - r_i

    if tmp_diff > diff:
        diff = tmp_diff

    for i in range(r_i_index, n):
        tmp_r_i = r_t[i]
        if tmp_r_i < r_i:
            r_i = tmp_r_i
            r_i_index = r_t.index(r_i)
            break

    if r_i_index + 1 >= n:
        break

print(diff)

Submission status: Time Limit Exceeded

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

max_margin = 1 - 10**9
for i in range(n):
    for j in range(i+1, n):
        margin = R[j] - R[i]
        if margin > max_margin:
            max_margin = margin

print(max_margin)

Submission status: Time Limit Exceeded

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

sa = R[N - 1] - R[N - 2]
for i in reversed(range(N)):
    for j in reversed(range(i)):
        tmp = R[i] - R[j]
        if tmp > sa:
            sa = tmp
print(sa)

Submission status: Time Limit Exceeded

Solution code:
#ALDS_1_1_D Maximum Profit

N=int(input())
A=[]
for i in range(N):
    A.append(int(input())) 
MAX= A[1]-A[0]
for i in range(1,N):
    for j in range(i):
        MAX=max(MAX,A[i]-A[j])
print(MAX)

Submission status: Time Limit Exceeded

Solution code:
def calcMax(i):
  now = numbers[i] 

  future_max = max(numbers[i+1:])
  #print(numbers[i+1:])
  t = numbers[i+1:]
  #print((max(t)))
  return future_max - now

n = int(input())

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

m = -1000000001
for i in range(len(numbers) - 1):
    temp = calcMax(i)
    #print("temp: " + str(temp))
    if temp > m:
        m = temp

print (m)

Submission status: Time Limit Exceeded

Solution code:
def calcMax(i):
  now = numbers[i] 

  future_max = max(numbers[i+1:])
  #print(numbers[i+1:])
  t = numbers[i+1:]
  #print((max(t)))
  return future_max - now

n = int(input())

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

m = -1000000001
p = -1000000001
for i in range(len(numbers) - 1):
    if numbers[i-1] >= numbers[i] or i == 0:
      temp = calcMax(i)
      #print("temp: " + str(temp))
      if temp > m:
          m = temp

print (m)

Submission status: Time Limit Exceeded

Solution code:

def calcMax(i):
  now = numbers[i] 

  future_max = max(numbers[i+1:])
  #print(numbers[i+1:])
  t = numbers[i+1:]
  #print((max(t)))
  return future_max - now

n = int(input())

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

m = -1000000001
for i in range(len(numbers) - 1):
    if i == 0 or i == len(numbers) - 1 or (numbers[i-1] >= numbers[i] and numbers[i] <= numbers[i+1]):
      temp = calcMax(i)
      #print("temp: " + str(temp))
      if temp > m:
          m = temp

print (m)

Submission status: Time Limit Exceeded

Solution code:

def calcMax(i):
  now = numbers[i] 

  future_max = max(numbers[i+1:])
  #print(numbers[i+1:])
  t = numbers[i+1:]
  #print((max(t)))
  return future_max - now

n = int(input())

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

m = -1000000001
for i in range(len(numbers) - 1):
    if i == 0 or i == len(numbers) - 1 or (numbers[i-1] >= numbers[i] and numbers[i] < numbers[i+1]) or (numbers[i-1] > numbers[i] and numbers[i] <= numbers[i+1]):
      temp = calcMax(i)
      #print("temp: " + str(temp))
      if temp > m:
          m = temp

print (m)

Submission status: Time Limit Exceeded

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

    ans = min(r) - max(r)
    for i in reversed(range(n)):
        for j in reversed(range(i)):
            tmp = r[i] - r[j]
            if tmp > ans:
                ans = tmp
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

    ans = min(r) - max(r)
    for i in reversed(range(1, n)):
        tmpr = r[:i]
        tmp = r[i] - min(tmpr)
        if tmp > ans:
            ans = tmp
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

t = []

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

buy = t[0]
sell = max(t[1:])
val = sell - buy

for i in range(n-1):
    m = max(t[i+1:])
    val2 = m - t[i]
    if val2 > val:
        buy = t[i]
        sell = m
        val = val2

print(val)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

t = []

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

buy = t[0]
prev_sell = max(t[1:])
val = prev_sell - buy

for i in range(n-1):
    if i == 0 or t[i - 1] < t[i]:
        continue
    prev_sell = max(t[i+1:])
    val2 = prev_sell - t[i]
    if val2 > val:
        val = val2

print(val)

Submission status: Time Limit Exceeded

Solution code:
def Maximum_Profit(A,N):
    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]
    return Max

N = int(input())
A = [] 
for i in range (N):
    A.append(input())
A = list(map(int,A))
print(Maximum_Profit(A,N))

Submission status: Time Limit Exceeded

Solution code:


def Maximum_Profit(A,N):
    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]
    return Max

N = int(input())
A = [] 
for i in range (N):
    A.append(input())
A = list(map(int,A))
print(Maximum_Profit(A,N))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [] 
for i in range (N):
    A.append(input())
A = list(map(int,A))
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:
#!/usr/bin/env python3
#coding:utf-8

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

maxdata = data[1] - data[0]

for i,n in enumerate(data):
    if len(data[i:]) == 1 :
        break

    nowdata = max(data[i+1:])-n
    if maxdata < nowdata:
        maxdata = nowdata

print(maxdata)

Submission status: Time Limit Exceeded

Solution code:
N = int(raw_input())
R = []
for i in range(0, N):
	R.append(int(raw_input()))
R.reverse()
max_num = -999999999

for x, i in enumerate(R[:N - 1]):
	for j in R[x + 1:]:		
		if max_num <(i - j):
			max_num = i - j

print max_num

Submission status: Time Limit Exceeded

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

ret = R[1] - R[0]
for i in range(N - 1):
    tmp = max(R[i + 1:]) - R[i]
    if tmp > ret:
        ret = tmp
print(ret)

Submission status: Time Limit Exceeded

Solution code:
while True:
    try:
        n = int(raw_input())
    except EOFError:
        break    
    
    ls = []
    for i in range(n):
        ls.append(int(raw_input()))
    
    maxvalue = -999999999999999999999999999999
    for k in range(len(ls)):
        for j in range(1,k+1):
            if ls[k]-ls[k-j] > maxvalue:
                maxvalue = ls[k]-ls[k-j]
    print maxvalue

Submission status: Time Limit Exceeded

Solution code:
while True:
    try:
        n = int(raw_input())
    except EOFError:
        break    
    
    ls = []
    for i in range(n):
        ls.append(int(raw_input()))
    
    maxvalue = -999999999999999999999999999999
    for k in range(len(ls)):
        if k == 0:
            continue
        else:
            temp = ls[k] - min(ls[:k])
        if  temp > maxvalue:
            maxvalue = temp
    print maxvalue

Submission status: Time Limit Exceeded

Solution code:
# for loop
n = int(raw_input())
ls = []
for i in range(n):
    ls.append(int(raw_input()))

ans = None
for k in range(n):
    for j in range(k+1,n):
        dif = ls[j]-ls[k]
        if ans is None:
            ans = dif
        elif ans < dif:
            ans = dif
print ans

Submission status: Time Limit Exceeded

Solution code:
amount = int(input())

numbers = [int(input()) for i in range(amount)]

max_profit = -1 * (numbers[0] - numbers[1])

for i in range(amount - 1):
    for j in range(i + 1, amount):
        if (-1 * (numbers[i] - numbers[j])) >= max_profit:
            max_profit = -1 * (numbers[i] - numbers[j])

print(max_profit)

Submission status: Time Limit Exceeded

Solution code:
import sys

num_list = int(sys.stdin.readline())
lines = sys.stdin.readlines()
nums = map(int, lines)

max_diff = -sys.maxint -1
for i in range(num_list) :
    for j in range(i+1, num_list) :
        diff = nums[j] - nums[i]
        if diff > max_diff :
            max_diff = diff

print max_diff

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8
n = int(input())
prices = [int(input()) for i in range(n)]
max_profit = None

for i in range(n-1):
    purchase = prices[i]
    for j in range(i+1,n):
        selling = prices[j]
        if (not max_profit) or max_profit < selling - purchase:
            max_profit = selling - purchase

print(max_profit)

Submission status: Time Limit Exceeded

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

result = l[1] - l[0]
for j in range(1, n):
    for i in range(0, j):
        if l[j] - l[i] > result:
            result = l[j] - l[i]
print(result)

Submission status: Time Limit Exceeded

Solution code:
n = int(raw_input())
R = [int(raw_input()) for i in xrange(n)]
L = [max(map(lambda n:n-x, R[i+1:])) for i, x in enumerate(R) if i < n-1]
print max(L)

Submission status: Time Limit Exceeded

Solution code:
n = int(raw_input())
R = [int(raw_input()) for i in xrange(n)]
L = [max(R[i+1:])-x for i, x in enumerate(R) if i < n-1]
print max(L)

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8
#1_1_D
n = int(input())
maxv = -2 * 10 ** 9
prices = [int(input()) for x in range(n)]

for i in range(1, n):
    for j in range(i):
        if prices[i] - prices[j] > maxv:
            maxv = prices[i] - prices[j]

print(maxv)

Submission status: Time Limit Exceeded

Solution code:
# import pdb
n = int(raw_input())

list = []
for x in xrange(n):
  list.append(int(raw_input()))

max = -10000000000000
for x in xrange(0, n - 1):
  for y in xrange(x + 1, n):
    # pdb.set_trace()
    temp = list[y] - list[x]
    if temp > max:
      max = temp

print max

Submission status: Time Limit Exceeded

Solution code:
num = n = int(input())
price = []
max_profit = -999999999999999

while(n>0):
    x = int(input())
    price.append(x)
    n -= 1
for i in range(1,num):
    for n in range(0,i):
        pro = price[i] - price[n]
        if pro > max_profit:
            max_profit = pro

print("{0}".format(max_profit))

Submission status: Time Limit Exceeded

Solution code:
import sys

x = []

for line in sys.stdin.readlines():
    x.append(int(line.strip()))

length = int(x[0])

del x[0]

max = -(10 ** 9)

for i in range(0, length - 1):
    for j in range(i + 1, length):
        sa = int(x[j]) - int(x[i])
        if max < sa:
            max = sa

print max

Submission status: Time Limit Exceeded

Solution code:
import sys

x = []

max = -(10**9)

for line in sys.stdin.readlines():
  x.append(line.strip())

length = int(x[0])

x.remove(x[0])

for i in range(0, length):
  for j in range(i + 1, length):
    sa = int(x[j]) - int(x[i])
    if max < sa:
      max = sa

print max

Submission status: Time Limit Exceeded

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

a.reverse()
sa=a[0]-a[1]
for i,e in enumerate(a):
    for j in a[i+1:]:
        sb=e-j
        if(sb>sa):
            sa=sb

print(sa)

Submission status: Time Limit Exceeded

Solution code:
n = int(raw_input())
R = list()
max = -10000000000

for i in range(n):
    R.append(int(raw_input()))
    for j in range(i):
        if max < R[i] - R[j]:
            max = R[i] - R[j]
            
print max

Submission status: Time Limit Exceeded

Solution code:
import sys
lines = sys.stdin.readlines()

n = lines[0]
lst = map(lambda x:int(x), lines[1:])

i = 0
for ri in lst:
    if i == 0:
        maxpro = lst[1] - lst[0]
    for rj in lst[i+1:]:
        sub = rj - ri
        if maxpro < sub:
            maxpro = sub
    i += 1

print maxpro

Submission status: Time Limit Exceeded

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

a.reverse()
sa=a[0]-a[1]
for i in range(1,n):
    sb=a[i-1]-min(a[i:])
    if(sb>sa):
        sa=sb

print(sa)

Submission status: Time Limit Exceeded

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

price_list = []

x = input()
x = int(x)

price_list.append(x)

max_profit_candidate = 1 - 10**9

for i in range(n - 1):
    x = input()
    x = int(x)
    diff = x - min(price_list)
    if diff > max_profit_candidate:
        max_profit_candidate = diff
    price_list.append(x)

print(max_profit_candidate)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
R = [int(input()) for i in list(range(N))]
maxv = -1000000000

for j in list(range(1, N)):
    for i in list(range(0, j)):
        maxv = max(maxv, R[j] - R[i])

print(maxv)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# input
n = int(input())
R = []
for i in range(n):
    R.append(int(input()))

# calc
maximum = -10**9
for i in range(n):
    for j in range(i+1, n):
        if R[j] - R[i] > maximum:
            maximum = R[j] - R[i]

# output
print(maximum)

Submission status: Time Limit Exceeded

Solution code:
def main():
	n=input()
	List_1=[]
	max=-1000000001
	for i in range(n):
		List_1.append(input())
		for j in range(i-1,-1,-1):
				if max<List_1[i]-List_1[j]:
					max=List_1[i]-List_1[j]
	print(max)

if __name__=='__main__':
	main()

Submission status: Time Limit Exceeded

Solution code:
def main():
	n=input()
	List_1=[]
	for i in range(n):
		List_1.append(input())
		if i==1:
			max=List_1[1]-List_1[0]
		elif i>1:
			for j in range(i-1,-1,-1):
				if max<List_1[i]-List_1[j]:
					max=List_1[i]-List_1[j]
	print(max)

if __name__=='__main__':
	main()

Submission status: Time Limit Exceeded

Solution code:
n = int(raw_input())
num_list = []
for i in xrange(n):
  num_list.append(int(raw_input()))
#print num_list

max = 1 - pow(10, 9)

for i in range(n - 1):
  for j in range(i + 1, n):
    tmp = num_list[j] - num_list[i]
#    print "i = %d, j = %d, tmp = %d" % (i, j, tmp)
    if tmp > max:
      max = tmp

print max

Submission status: Time Limit Exceeded

Solution code:
n = int(raw_input())
num_list = [int(raw_input()) for i in xrange(n)]
#print num_list

ans = 1 - pow(10, 9)

for i in range(n - 1):
  max_num = max(num_list[i+1:])
  tmp = max_num - num_list[i]
  if tmp > ans:
    ans = tmp

print ans

Submission status: Time Limit Exceeded

Solution code:
n = int(raw_input())
num_list = [int(raw_input()) for i in xrange(n)]
#print num_list

ans = max(num_list[1:]) - num_list[0]
chk = num_list[0]
# print "ans=%d, chk=%d" % (ans, chk)

for i in range(1, n - 1):
  if num_list[i] >= chk:
    continue
  max_num = max(num_list[i+1:])
  # print max_num
  tmp = max_num - num_list[i]
  if tmp > ans:
    ans = tmp
  # print "i = %d, tmp = %d, ans = %d" % (i, tmp, ans)

print ans

Submission status: Time Limit Exceeded

Solution code:
import functools

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

benefit = [[rj - ri for j,rj in enumerate(R[i:]) if j+i > i] for i,ri in enumerate(R)]
print(max(functools.reduce(lambda a,b: a+b, benefit)))

Submission status: Time Limit Exceeded

Solution code:
max = 1-10**9
i = 0
j = 0
n_max = 0

n_max = int(raw_input())
price = [0]*n_max
for i in range(n_max):
    price[i] = int(raw_input())
for i in range(n_max):
    for j in range(i+1, n_max):
        if max <= (price[j] - price[i]):
            max = price[j] - price[i]
print max

Submission status: Time Limit Exceeded

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

max = R[1] - R[0]
for i in range(N - 1):
    for j in range(i + 1):
        dif = R[i+1] - R[j]
        if dif > max:
            max = dif

print max

Submission status: Time Limit Exceeded

Solution code:
dif_max = 1-10**9
max = 1
min = 10**9
n_max = 0
n_max = int(raw_input())

price = [0]*n_max
for i in range(0, n_max):
    price[i] = int(raw_input())
for i in range(0, n_max-1):
    for j in range(0, n_max):
        if j <= i:
            if min >= price[j]:
                min = price[j]
        else:
            if max <= price[j]:
                max = price[j]
    if dif_max <= max - min:
        dif_max = max - min
    max = 1
    min = 10**9
print dif_max

Submission status: Time Limit Exceeded

Solution code:
dif_max = 1-10**9
max = 1
min = 10**9
n_max = 0
n_max = int(raw_input())
 
price = [0]*n_max
for i in range(0, n_max):
  price[i] = int(raw_input())
for i in range(0, n_max-1):
  if min >= price[i]:
      min = price[i]
  for j in range(i+1, n_max):
      if max <= price[j]:
          max = price[j]
  if dif_max <= max - min:
      dif_max = max - min
  max = 1
  min = 10**9
print dif_max

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
DifMax = -99999999999

R = [int(input())]
for i in range(1, n):
  RMin = min(R)
  R.append(int(input()))
  if DifMax < R[i] - RMin:
    DifMax = R[i] - RMin

print(DifMax)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
DifMax = -999999999

R = [int(input())]
for i in range(1, n):
  RMin = min(R)
  R.append(int(input()))
  if DifMax < R[i] - RMin:
    DifMax = R[i] - RMin

print(DifMax)

Submission status: Time Limit Exceeded

Solution code:
#Reference : http://qiita.com/lethe2211/items/6cbade2bc547649bc040
n = input()

R = []
for i in range(n):
    R.append(input())
gain_list = []
for i in range(n):
    gain_list.append(-pow(10, 9))

start_point = 0
peak = 0

while (start_point < n - 1):
    for i in range(start_point + 1, n):
         diff = R[i] - R[start_point]
         if (diff >= gain_list[start_point]):
             gain_list[start_point] = diff
             peak = i
    for i in range(start_point, peak):
        gain_list[i] = R[peak] - R[i]
    start_point = peak

print max(gain_list)

Submission status: Time Limit Exceeded

Solution code:
#Reference : http://qiita.com/lethe2211/items/6cbade2bc547649bc040
n = input()

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

start_point = 0
peak = 0
max_diff = -pow(10, 9)

while (start_point < n - 1):
    diff = -pow(10, 9)
    for i in range(start_point + 1, n):
         diff_temp = R[i] - R[start_point]
         if (diff_temp >= diff):
             diff = diff_temp
             peak = i
    for i in range(start_point, peak):
        diff_temp = R[peak] - R[i]
        if (diff_temp > max_diff):
            max_diff = diff_temp
    start_point = peak

print max_diff

Submission status: Time Limit Exceeded

Solution code:
n = input()
m = [0] * n
max = [0] * n
kijun = [0] * n
rieki = [0] * n
max_rieki = 0
for i in xrange(n):
 m[i] = input()
 
 
for i in xrange(n-1):
 max[i] = m[i+1] 
 kijun[i] = m[i]
 for j in xrange(i+1,n): 
  if max[i] < m[j]:
      max[i] = m[j]
 rieki[i] = max[i] - kijun[i]
max_rieki = rieki[0]
for i in xrange(1,n-1):
  if rieki[i] > max_rieki:
   max_rieki = rieki[i]
 
print max_rieki

Submission status: Time Limit Exceeded

Solution code:
n = input()
m = [0] * n
max = [0] * n
kijun = [0] * n
rieki = [0] * n
max_rieki = 0
for i in xrange(n):
 m[i] = input()
 
 
for i in xrange(n-1):
 max[i] = m[i+1] 
 kijun[i] = m[i]
 for j in xrange(i+1,n): 
  if max[i] < m[j]:
      max[i] = m[j]
 rieki[i] = max[i] - kijun[i]
 if i == 0:
  max_rieki = rieki[0]
 if rieki[i] > max_rieki:
  max_rieki = rieki[i]

print max_rieki

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Here your code !
n = input()
m = [0] * n
max = [0] * n
kijun = [0] * n
rieki = [0] * n
max_rieki = 0


for i in xrange(n):
 m[i] = input()
 
 
for i in xrange(n):
 if i != n-1:    
  max[i] = m[i+1] 
  kijun[i] = m[i]
  for j in xrange(i+1,n): 
   if max[i] < m[j]:
      max[i] = m[j]
  rieki[i] = max[i] - kijun[i]
  if i == 0:
   max_rieki = rieki[0]
  if rieki[i] > max_rieki:
   max_rieki = rieki[i]

print max_rieki

Submission status: Time Limit Exceeded

Solution code:
n = input()
m = [0] * n
max = [0] * n
kijun = [0] * n
rieki = [0] * n
max_rieki = 0


for i in xrange(n):
 m[i] = input()
 
 
for i in xrange(n):
 if i != n-1:    
  max[i] = m[i+1] 
  kijun[i] = m[i]
  for j in xrange(i+1,n): 
   if max[i] < m[j]:
      max[i] = m[j]
  rieki[i] = max[i] - kijun[i]
  if i == 0:
   max_rieki = rieki[0]
  if rieki[i] > max_rieki:
   max_rieki = rieki[i]

print max_rieki

Submission status: Time Limit Exceeded

Solution code:
n = input()
m = [0] * n
max = [0] * n
kijun = [0] * n
rieki = [0] * n
max_rieki = -1*10**9


for i in xrange(n):
 m[i] = input()
 
 
for i in xrange(n):
 if i != n-1:    
  for j in xrange(i+1,n): 
   if max_rieki < m[j] - m[i]:
      max_rieki = m[j] - m[i]


print max_rieki

Submission status: Time Limit Exceeded

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

maxsub = r_s[1] - r_s[0]
mini = r_s[0]

for i in range(n-1):
    if r_s[i] > mini:
        continue

    mini = r_s[i]
    for j in range(i+1, n):
        if maxsub < (r_s[j] - r_s[i]):
            maxsub = r_s[j] - r_s[i]

print(maxsub)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = []
for i in range(N):
    a.append(int(input()))
mx = -10**12
for j in range(1, N):
    for i in range(j):
        mx = max(mx, a[j] - a[i])
print(mx)

Submission status: Time Limit Exceeded

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

Max=num_list[1]-num_list[0]

for i in range(n-1):
    for j in range(i+1,n):
        if Max<num_list[j]-num_list[i]:
            Max=num_list[j]-num_list[i]

print(Max)

Submission status: Time Limit Exceeded

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

profit = R[1] - R[0]
for i in range(n):
    for j in range(i+1, n):
        if R[j] - R[i] > profit:
            profit = R[j] - R[i]
print "%d" % profit

Submission status: Time Limit Exceeded

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

profit = R[n-1] - R[0]
after = R[n-1]
for i in range(n):
    if R[n-1-i] < after and i != 0:
        continue
    for j in range(n-i-1):
        if R[n-1-i] - R[j] > profit:
            profit = R[n-1-i] - R[j]
            after = R[n-1-i]
print "%d" % profit

Submission status: Time Limit Exceeded

Solution code:

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

ans = -9999999999
num = num[::-1]
for i in xrange(len(num)):
    for j in xrange(len(num)-(i+1)):
        if ans < num[i] - num[j + i + 1]:
            ans = num[i] - num[j + i + 1]
print ans

Submission status: Time Limit Exceeded

Solution code:
a=int(input())
b=[]
for i in range(a):
    b.append(int(input()))
c=-1000000000
for i in range(a):
    for ii in range(1+i,a):
        if b[ii]-b[i]>c:c=b[ii]-b[i]
print(str(c))

Submission status: Time Limit Exceeded

Solution code:
a=int(input())
b=[]
for i in range(a):
    b.append(int(input()))
c=b[1]-b[0]
for i in range(a):
    for ii in range(1+i,a):
        if b[ii]-b[i]>c:c=b[ii]-b[i]
print(str(c))

Submission status: Time Limit Exceeded

Solution code:
a=int(input())
b=[int(input()),int(input())]
for i in range(a-2):
    b.append(int(input()))
    if b[-1]<b[-2] and min(b)!=b[-1]:
        b.pop()
c=b[1]-b[0]
for i in range(len(b)):
    for ii in range(1+i,len(b)):
        if b[ii]-b[i]>c:c=b[ii]-b[i]
print(str(c))

Submission status: Time Limit Exceeded

Solution code:
a=int(input())
b=[int(input())]
for i in range(a-1):
    b.append(int(input()))
    if b[-1]<b[-2] and min(b)!=b[-1]:
        b.pop()
c=b[1]-b[0]
for i in range(1,len(b)):
    if max(b[i:])-min(b[:i])>c:c=max(b[i:])-min(b[:i])
print(str(c))

Submission status: Time Limit Exceeded

Solution code:
#coding: UTF-8

N = int(input())

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

ans = []

for i in range(N-1):
    Rj = int(a.pop(0));
    tmp = max(a);
    ans.append(tmp - Rj);

print(max(ans))

Submission status: Time Limit Exceeded

Solution code:
#coding: UTF-8

N = int(input())

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

ans = set()

for i in range(N-1):
    Rj = int(a.pop(0));
    tmp = max(a);
    ans.add(tmp - Rj);

print(max(ans))

Submission status: Time Limit Exceeded

Solution code:
input_profit = []
for x in xrange(input()):
    input_profit.append(input())
max_profit=input_profit[1]-input_profit[0]
for i in xrange(len(input_profit)-1):
    min_profit = input_profit[i]
    candidate = max(input_profit[i+1:])-min_profit
    if candidate>max_profit:
        max_profit=candidate
print max_profit

Submission status: Time Limit Exceeded

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

n = int(raw_input())
R_List = []
Max = 0
for i in range(n):
    R_List.append(int(raw_input()))
    if i == 0:
        continue
    elif i == 1:
        Max = R_List[1]-R_List[0]
    else:
        for j in range(i):
            Max = max(Max, R_List[i]-R_List[j])
print Max

Submission status: Time Limit Exceeded

Solution code:
import math
A = []
N = int(input())
maxdiff = 0
for n in range(N):
    A.append(int(input()))
S = tuple(A)
Smax = ((S[i]-min(S[:i])) for i in range(1, N))
print(max(Smax))

Submission status: Time Limit Exceeded

Solution code:
import sys

# ?????§???????±??????????
def get_max(data):
    now_max = None
    for i in range(0, len(data)-1):
        start_val = data[i]
        for j in range(i+1, len(data)):
            if now_max is None or data[j]-start_val > now_max:
                now_max = data[j] - start_val
    return now_max

# ??\???????????????????????????
data = []
line_num = int(sys.stdin.readline().rstrip())
while True:
    input_data = sys.stdin.readline()
    if not input_data:
        break
    input_data = int(input_data.rstrip())
    data.append(input_data)

result = get_max(data)
print(result)

Submission status: Time Limit Exceeded

Solution code:
N=input()
input = [int(input()) for i in range(int(N))]
max=-10000000000
for i,x in enumerate(input):
	for j,y in enumerate(input):
		if j>i:
			if max < input[j]-input[i]:
				max = input[j]-input[i]
print(max)

Submission status: Time Limit Exceeded

Solution code:
n = input()
R = [input()] 
Rmin = 0
maxdif = -999999999
for i in xrange(n-1):
    Rt = input()
    for j in xrange(Rmin, len(R)):
        if (Rt - R[j]) > maxdif:
            maxdif = Rt - R[j]
    if Rt < Rmin:
        Rmin = i + 1
    R.append(Rt)

print maxdif

Submission status: Time Limit Exceeded

Solution code:
n = input()
R = [input()] 
Rmin = 0
maxdif = -999999999
for i in xrange(n-1):
    Rt = input()
    for j in xrange(Rmin, len(R)):
        if (Rt - R[j]) > maxdif:
            maxdif = Rt - R[j]
    if Rt < R[Rmin]:
        Rmin = i + 1
    R.append(Rt)

print maxdif

Submission status: Time Limit Exceeded

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

def profit(values):
    sorted_values = sorted(values)
    minimum = sorted_values[0]
    maximum = sorted_values[-1]
    diff_list = []
    while values != []:
        diff = minimum - maximum
        start = values[0]
        for v in values[1:]:
            tmp_diff = v - start
            if tmp_diff > diff:
                diff = tmp_diff
        diff_list.append(diff)
        values.remove(values[0])
    diff_list.sort(reverse = True)
    return diff_list[0]


print(profit(values))

Submission status: Time Limit Exceeded

Solution code:
arr = []
for i in range(int(input())):
    arr.append(int(input()))
m = 0
for i in range(len(arr)-1):
    for j in range(i+1, len(arr)):
        if i == 0 and j == 1:
            m = arr[j] - arr[i]
        else:
            m = max(m, arr[j] - arr[i])
print(m)

Submission status: Time Limit Exceeded

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

for i in range(0, n-1):
    for j in range(i+1, n):
        maxv = R[j] - R[i] if R[j] - R[i] > maxv else maxv

print(maxv)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
R = [int(input()) for x in range(n)]
maxv = -2000000000

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

print(maxv)

Submission status: Time Limit Exceeded

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

min_i = N-2
max_i = N-1

for i in range(N-1)[::-1]:
    for j in range(i+1, N):
        if r[j] - r[i] > r[max_i] - r[min_i]:
            max_i = j
            min_i = i


print(r[max_i] - r[min_i])