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:
n = input()
a = [input() for i in range(n)]
i = 0
j = 1
max = a[j] - a[i]

while n-1 > i:
  j = i+1
  while n-1 > j:
    if max < a[j] - a[i]:
      max = a[j] - a[j]
    j += 1
  i += 1

print max

Submission status: Wrong Answer

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

while n-1 > i:
  j = i+1
  while n-1 > j:
    if max < a[j] - a[i]:
      max = a[j] - a[j]
    j += 1
  i += 1

print '{0}',format(max)

Submission status: Wrong Answer

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

while n > i:
  j = i+1
  while n > j:
    if max < a[j] - a[i]:
      max = a[j] - a[j]
    j += 1
  i += 1

print '{0}',format(max)

Submission status: Wrong Answer

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

while n > i:
  j = i+1
  while n > j:
    if max < a[j] - a[i]:
      max = a[j] - a[j]
    j += 1
  i += 1

print '{0}',format(max)

Submission status: Wrong Answer

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

while n-1 > i:
  j = i+1
  while n > j:
    if max < a[j] - a[i]:
      max = a[j] - a[j]
    j += 1
  i += 1

print '{0}',format(max)

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
minv =  int(raw_input())
maxv = (-1)*10**9
a = int(raw_input())
b = a- minv  


for j in range(n-1):
    if minv >= a:
       minv = a
    if maxv <= b:
       maxv = b
print maxv

Submission status: Wrong Answer

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

while n-1 > i:
  j = i+1
  while n-1 >= j:
    if max < a[j] - a[i]:
      max = a[j] - a[j]
    j += 1
  i += 1

print '{0}',format(max)

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
minv =  int(raw_input())
maxv = -1*10**9
a = int(raw_input())
b = a- minv  
for j in range(n-1):
    if minv > a:
       minv = a
    if maxv < b:
       maxv = b
print maxv

Submission status: Wrong Answer

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

while n-1 > i:
  j = i+1
  while n > j:
    if max <= a[j] - a[i]:
      max = a[j] - a[j]
    j += 1
  i += 1

print '{0}',format(max)

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
minv = int(raw_input())
maxv = -1*10**9
a = int(raw_input())
b = a- minv  
for j in range(n-1):
    if minv > a:
       minv = a
    if maxv < b:
       maxv = b
print maxv

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
minv = int(raw_input())
maxv = -1*10**9
a = int(raw_input())
b = a- minv  

for j in range(n-1):
  
    if maxv < b:
       maxv = b 
    if minv > a:
       minv = a
print maxv

Submission status: Wrong Answer

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

while n-1 > i:
  j = i+1
  while n > j:
    if max <= a[j] - a[i]:
      max = a[j] - a[j]
    j += 1
  i += 1

print '{0}',format(2)

Submission status: Wrong Answer

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

while n-1 > i:
  j = i+1
  while n > j:
    if max <= a[j] - a[i]:
      max = a[j] - a[j]
    j += 1
  i += 1

print 2

Submission status: Wrong Answer

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

while n-1 > i:
  j = i+1
  while n-1 > j:
    if max <= a[j] - a[i]:
      max = a[j] - a[j]
    j += 1
  i += 1

print 2

Submission status: Wrong Answer

Solution code:

n=input()
R=[0]*n
max=0
min=input()

for i in range(n-1):
    R[i]=input()
    if min > R[i]:
      min = R[i]
    if max < R[i]-min:
      max = R[i]-min
print max

Submission status: Wrong Answer

Solution code:
n=input()
R=[0]*n
max=0
min=input()

for i in range(n-1):
    R[i]=input()
    if min > R[i]:
      min = R[i]
    if max < R[i]-min:
      max = R[i]-min
print max

Submission status: Wrong Answer

Solution code:
n = input()
maxv = -1 * 10**9
minv = input()

for j in range(1,n-1):
  v = input()
  if maxv < v - minv:
    maxv = v - minv
  if minv > v:
    minv = v

print maxv

Submission status: Wrong Answer

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

Solution code:
def main():
    
    N = input()
    a = [input() for y in range(N)]
    a_max = -10**9
    for i in xrange(1,len(a)-1):
        if (max(a[(i+1):]) - a[i]) >= a_max:
            a_max = max(a[(i+1):]) - a[i]
    return a_max

main()

Submission status: Wrong Answer

Solution code:
def main():
    
    N = input()
    a = [input() for y in range(N)]
    a_max = -10**9
    for i in xrange(1,len(a)-1):
        if (max(a[(i+1):]) - a[i]) >= a_max:
            a_max = max(a[(i+1):]) - a[i]
    print a_max
    return 0

main()

Submission status: Wrong Answer

Solution code:
def main():
    
    N = input()
    a = [input() for y in range(N)]
    a_max = -10**9
    a_min = a[1]
    for j in xrange(2,len(a)-1):
        if a[j] - a_min > a_max:
            a_max = a[j] - a_min
        if a[j] < a_min:
            a_min = a[j]
    print a_max
        
main()

Submission status: Wrong Answer

Solution code:
min = 2000000
max = 1 - 10 ** 9
for _ in range(int(input())):
    r = int(input())
    if (r - min) > max:
        max = r - min
    if r < min:
        min = r
print(max)

Submission status: Wrong Answer

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

for i in range(0, len(R)):
    for j in range(i, len(R)):
        if R[j] - R[i] > max:
            max = R[j] - R[i]

print max

Submission status: Wrong Answer

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

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

print maxv

Submission status: Wrong Answer

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

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

if maxv >  0:
    print maxv
if maxv <= 0:
    print -1

Submission status: Wrong Answer

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

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

if maxv >= 0:
    print maxv
if maxv <  0:
    print -1

Submission status: Wrong Answer

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

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

print maxv

Submission status: Wrong Answer

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

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

print maxv

Submission status: Wrong Answer

Solution code:
max_v = 1000000000
min_v = -1000000000

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

for r in data:
    max_v = max(max_v, r - min_v)                                               
    min_v = min(min_v, r)
    
print(max_v)

Submission status: Wrong Answer

Solution code:
max_v = 1000000000
min_v = -1000000000

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

for r in data:
    max_v = max(max_v, r - min_v)                                               
    min_v = min(min_v, r)
    
print(N)

Submission status: Wrong Answer

Solution code:
max_v = 1000000000
min_v = -1000000000

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

for r in data:
    max_v = max(max_v, r - min_v)                                               
    min_v = min(min_v, r)
    
print(3)

Submission status: Wrong Answer

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

min_value = data.pop(0)
max_value = -100000000
print(data)
for d in data:
    max_value = max(d, max_value)
    min_value = min(d, min_value) 
print(max_value - min_value)

Submission status: Wrong Answer

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

min_value = data.pop(0)
max_value = -100000000
for d in data:
    max_value = max(d, max_value)
    min_value = min(d, min_value) 
print(max_value - min_value)

Submission status: Wrong Answer

Solution code:
n = input()

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

min_v = R[0]
max_v = -pow(10, 2)
for i in range(1, n):
    temp = R[i] - min_v
    if (temp >= max_v):
        max_v = temp
    temp = R[i]
    if (min_v >= temp):
        min_v = temp
print max_v

Submission status: Wrong Answer

Solution code:
n = input()

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

min_v = R[0]
max_v = -100000
for i in range(1, n):
    temp = R[i] - min_v
    if (temp >= max_v):
        max_v = temp
    temp = R[i]
    if (min_v >= temp):
        min_v = temp
print max_v

Submission status: Wrong Answer

Solution code:
n = input()

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

min_v = R[0]
max_v = -10000000
for i in range(1, n):
    temp = R[i] - min_v
    if (temp >= max_v):
        max_v = temp
    temp = R[i]
    if (min_v >= temp):
        min_v = temp
print max_v

Submission status: Wrong Answer

Solution code:
n = input()

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

min_v = R[0]
max_v = -100000000
for i in range(1, n):
    temp = R[i] - min_v
    if (temp >= max_v):
        max_v = temp
    temp = R[i]
    if (min_v >= temp):
        min_v = temp
print max_v

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a=int(input())
b=[]
for i in range(a):
    b.append(int(input()))
c=-40000001
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: Wrong Answer

Solution code:
a=int(input())
b=[]
for i in range(a):
    b.append(int(input()))
c=-10**-9-10
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: Wrong Answer

Solution code:
a=int(input())
b=[]
for i in range(a):
    b.append(int(input()))
c=-10**(-10)-10
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: Wrong Answer

Solution code:
a=int(input())
b=[int(input()),input()]
for i in range(a-2):
    b.append(int(input()))
    if b[-1]>b[-2]:
        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: Wrong Answer

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

Solution code:
#coding: UTF-8

N = int(input())

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

ans = set()

maxv = -9999999999
minv = a[0]
for i in range(1,N-1):
    if (a[i] - minv) > maxv:
        maxv = a[i] - minv
    if a[i] < minv:
        minv = a[i]

print(maxv)

Submission status: Wrong Answer

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

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

	print(maxv)

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
R_list = [int(raw_input()) for _ in range(n)]

min_R = int(1e10)
ans = -int(1e6)
for R in R_list:
    ans = max(ans, R - min_R)
    min_R = min(min_R, R)

print ans

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
R_list = [int(raw_input()) for _ in range(n)]

min_R = int(1e11)
ans = -int(1e7)
for R in R_list:
    ans = max(ans, R - min_R)
    min_R = min(min_R, R)

print ans

Submission status: Wrong Answer

Solution code:
import math
A = []
N = int(input())
maxdiff = 0
for n in range(N):
    A.append(int(input()))
R = tuple(A)

Dmax = R[1] -R[0]
Rmin = R[0]

for i in range(1, N):
    if R[i] > R[i-1]:
        if R[i] - Rmin > Dmax:
            Dmax = R[i] -Rmin
    if R[i] < Rmin:
        Rmin = R[i]

print(Dmax)

Submission status: Wrong Answer

Solution code:
import math
A = []
N = int(input())
maxdiff = 0
for n in range(N):
    A.append(int(input()))
R = tuple(A)

Dmax = R[1] -R[0]
Rmin = R[0]

for i in range(1, N):
    if R[i] >= R[i-1]:
        if R[i] - Rmin > Dmax:
            Dmax = R[i] -Rmin
    if R[i] < Rmin:
        Rmin = R[i]
    print(R[i], Dmax, Rmin)

print(Dmax)

Submission status: Wrong Answer

Solution code:
mn, mx, dif = 1E9, 0, -1E9
n = int(input())
for i in range(n):
    r = int(input())
    if r - mn > dif:
        dif = r - mn
    if r < mn:
        mn = r
        mx = 0
print(dif)

Submission status: Wrong Answer

Solution code:
#cording by utf-8

n = int(input())
#maxv ?????§???
#minv ????°????
minv = int(input()) #?????????????°????
maxp = int(input()) #??????????????§???
maxp = maxp - minv
for i in range(2,n):
    stock = int(input())
    if minv > stock:
        minv = stock
    else:
        profit = stock - minv
        if profit > maxp:
            maxp = profit

print(maxp)

Submission status: Wrong Answer

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 = []
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: Wrong Answer

Solution code:
input_n = input()
min_profit = input()
max_profit = input()-min_profit
for i in xrange(input_n-2):
    input_profit = input()
    tmp = input_profit-min_profit
    if max_profit<tmp:
        max_profit = tmp
    if min_profit>input_profit:
        min_profit = input_profit
print max_profit

Submission status: Wrong Answer

Solution code:
N=input()
input = [int(input()) for i in range(int(N))]
max=-1000000
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: Wrong Answer

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

Rmin = 0
Rmax = 0
maxdif = R[1] - R[0]

for i in xrange(1, n):
    if R[Rmin] > R[i]:
        Rmin = i
        Rmax = i
    if R[i] > R[Rmax]:
        maxdif = R[i] - R[Rmin]
        Rmax = i

print maxdif

Submission status: Wrong Answer

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

Rmin = 0
Rmax = 0
maxdif = R[1] - R[0]

for i in xrange(1, n):
    if R[Rmin] > R[i]:
        Rmin = i
        Rmax = i
    if R[i] > R[Rmax]:
        Rmax = i
        if R[Rmax] - R[Rmin] > maxdif:
            maxdif = R[Rmax] - R[Rmin]

print maxdif

Submission status: Wrong Answer

Solution code:
# input
n = input()
R = [input() for i in xrange(n)]

# initilize
Rmin = 0
Rmax = 0
maxdif = R[1] - R[0]

# processing
for i in xrange(1, n):
    if R[Rmin] > R[i]:
        Rmin = i
        Rmax = i
    if R[i] > R[Rmax]:
        Rmax = i
    if R[Rmax] - R[Rmin] > maxdif:
        maxdif = R[Rmax] - R[Rmin]

# output
print maxdif

Submission status: Wrong Answer

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

Rmin = n
maxdif = R[1] - R[0]

while Rmin > 0:
    tRmin = R.index(min(R[0:Rmin]))
    Rmax = R.index(max(R[tRmin:Rmin]))
    Rmin = tRmin
    if Rmin == Rmax:
        break
    if (R[Rmax] - R[Rmin]) > maxdif:
        maxdif = R[Rmax] - R[Rmin]

print maxdif

Submission status: Wrong Answer

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

Rmin = n
maxdif = R[1] - R[0]

while Rmin > 0:
    tRmin = R.index(min(R[0:Rmin]))
    Rmax = R.index(max(R[tRmin:Rmin]))
    if tRmin == Rmax and tRmin > 0:
        tRmin-=1
    Rmin = tRmin
    if (R[Rmax] - R[Rmin]) > maxdif:
        maxdif = R[Rmax] - R[Rmin]

print maxdif

Submission status: Wrong Answer

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

Rmin = n
maxdif = R[1] - R[0]

while Rmin > 0:
    tRmin = R.index(min(R[0:Rmin]))
    Rmax = R.index(max(R[tRmin:Rmin]))
    if tRmin == Rmax:
        if tRmin > 0:
            tRmin-=1
        else:
            break
    Rmin = tRmin
    print tRmin, Rmax, R[Rmax]-R[Rmin]
    if (R[Rmax] - R[Rmin]) > maxdif:
        maxdif = R[Rmax] - R[Rmin]

print maxdif

Submission status: Wrong Answer

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

Rmin = n
maxdif = R[1] - R[0]

while Rmin > 0:
    tRmin = R.index(min(R[0:Rmin]))
    Rmax = R.index(max(R[tRmin:Rmin]))
    if tRmin == Rmax:
        if tRmin > 0:
            tRmin-=1
        else:
            break
    Rmin = tRmin
    if (R[Rmax] - R[Rmin]) > maxdif:
        maxdif = R[Rmax] - R[Rmin]

print maxdif

Submission status: Wrong Answer

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

maxv = -99999999
minimum = values[0]

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

print(maxv)

Submission status: Wrong Answer

Solution code:
n = int(input())
minv = int(input())
maxv = int(input()) - minv

for _ in range(n-2):
    rt = int(input())
    maxv = max([maxv, rt - minv])
    minv = min([minv, rt])

print(maxv)

Submission status: Wrong Answer

Solution code:
n = int(input())
minv = int(input())
maxv = -200000

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

print(maxv)

Submission status: Wrong Answer

Solution code:
import sys

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

for i in map(int,sys.stdin.readlines()):
    if 0 < mx < i - mn:
        mx = i - mn
    elif 0 > i-mn > mx:
        mx = i - mn
        mn = i
    elif mn > i:
        mn = i

print(mx)

Submission status: Wrong Answer

Solution code:
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_D
sample_input = '''
6
5
3
1
3
4
3
'''
give_sample_input = False
if give_sample_input:
  sample_input_list = sample_input.split()
  def input():
    return sample_input_list.pop(0)

import math

numOfData = int(input())
max_diff = -1
min_val = 0
for n in range(numOfData):
	val = int(input())
	if n == 0:
		min_val = val
	else:
		min_val = min(val, min_val)
	max_diff = max(val - min_val, max_diff)

print(max_diff)

Submission status: Wrong Answer

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

min = r[0]
max = -1000000

for j in r[1:]:
    if j - min > max:
        max = j - min
    if min > j:
        min = j

print(max)

Submission status: Wrong Answer

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

min = r[0]
max = -10000000000

for j in r[1:]:
    if j - min > max:
        max = j - min
    if min > j:
        min = j

Submission status: Wrong Answer

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

min = r[0]
max = -10000000

for j in r[1:]:
    if j - min > max:
        max = j - min
    if min > j:
        min = j

print(max)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python


def main():
  times = int(input())
  min_rate = 10 ** 9
  maxv = - min_rate
  for _ in range(0, times):
    rate = int(input())
    if rate < min_rate:
      min_rate = rate
    if rate - min_rate > maxv:
      maxv = rate - min_rate
  print(maxv)
  return 0


if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python


def main():
  times = int(input())
  min_rate = None
  maxv = None
  for _ in range(0, times):
    rate = int(input())

    if min_rate is None:
      min_rate = rate
    elif maxv is None:
      maxv = rate - min_rate
    elif rate < min_rate:
      min_rate = rate
    elif rate - min_rate > maxv:
      maxv = rate - min_rate
  print(maxv)
  return 0


if __name__ == '__main__':
  main()

Submission status: Wrong Answer

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

min_v = float("inf")
ans = -float("inf")
for r in R:
    if r < min_v:
        min_v = r
    if (r - min_v) > ans:
        ans = r - min_v
print ans

Submission status: Wrong Answer

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

min_v = float("inf")
ans = -float("inf")
for r in R:
    if (r - min_v) > ans:
        ans = r - min_v
    if r < min_v:
        min_v = r
print ans

Submission status: Wrong Answer

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

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

print(maxv)

Submission status: Wrong Answer

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

for j in range(1, n):
    maxv = R[j] - minv if R[j] - minv > maxv else maxv
    minv = R[j] if R[j] < minv else minv
    print('??????{0}-{1}??§{2}??§???'.format(R[j], minv, R[j] - minv))

print(maxv)

Submission status: Wrong Answer

Solution code:
def getsub(arr):
    minv = arr[0]
    maxdist = arr[1] - minv

    for v in arr[2:]:
        # update maxdist
        # tmpmaxdist = v - minv
        # if tmpmaxdist > maxdist:
            # maxdist = tmpmaxdist
        maxdist = max(maxdist, v- minv)

        # update minv
        # if v < minv:
            # minv = v
        minv = min(minv, v)

    return maxdist

def main():
    # get input
    N = int(input())
    arr = [int(input()) for i in range(N)]

    # get sub
    print(getsub(arr))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

print(maxv)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

n = int(input())

max_val = -2000000
min_val = int(input())

for i in range(n - 1):
    t = int(input())
    max_val = max(max_val, t - min_val)
    min_val = min(min_val, t)

print(max_val)

Submission status: Wrong Answer

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

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

print(max - min)

Submission status: Wrong Answer

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

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


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

Submission status: Wrong Answer

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]:
    if r[i] < r[i+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])

Submission status: Wrong Answer

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]:
    if (r[i] - r[i+1]) * r[max_i] - r[min_i] > 0:
        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])

Submission status: Wrong Answer

Solution code:
num = int(input())
minnum = 10 ** 9 + 1
ans = 0
for n in range(num):
    newnum = int(input())
    ans = max(ans,newnum - minnum)
    minnum = min(minnum,newnum)
print(ans)

Submission status: Wrong Answer

Solution code:
num = int(input())
minnum = 10 ** 9 + 1
ans = -(10 ** 9 + 1)
for n in range(num):
    newnum = int(input())
    ans = max(ans,newnum - minnum)
    minnum = min(minnum,newnum)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = []
for i in range(N):
    a.append(int(input()))
max_profit = a[1] - a[0]
for i in range(2,N):
	if a[i] - a[i-1] > max_profit:
		max_profit = a[i] - a[i-1]
print(str(max_profit))

Submission status: Wrong Answer

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

min = r[0]
max = -99999999

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

print(max)

Submission status: Wrong Answer

Solution code:
n = int(input())
ps = [int(input()) for _ in range(n)]
maxpro = 0
for i, p in enumerate(ps[:-1]):
  pro = max(ps[i + 1:]) - p
  maxpro = max(pro, maxpro)
print(maxpro)

Submission status: Wrong Answer

Solution code:
n = int(input())
ps = [int(input()) for _ in range(n)]
maxpro = -1
for i, p in enumerate(ps[:-1]):
  pro = max(ps[i + 1:]) - p
  maxpro = max(pro, maxpro)
print(maxpro)

Submission status: Wrong Answer

Solution code:
n = int(input())
nums = [int(input()) for i in range(n)]
ans = -100000000

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

Submission status: Wrong Answer

Solution code:
n = int(input())
nums = [int(input()) for i in range(n)]
temp = nums[1] - nums[0]
p = nums[0]

for i in nums[1:]:
    if i - p > temp:
        ans = i- p
    if i < p:
        p = i
print(ans)

Submission status: Wrong Answer

Solution code:
n=input()
print n*n*n

Submission status: Wrong Answer

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

minv = n[0]
maxv = -99999999999

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

print(maxv)

Submission status: Wrong Answer

Solution code:
#coding:UTF-8

def MP(n,a):
    minv=a[0]
    maxv=0
    for i in range(1,n):
        if maxv<a[i]-minv:
            maxv=a[i]-minv
        if minv>a[i]:
            minv=a[i]    
    print(maxv)
if __name__=="__main__":
    n=int(input())
    a=[]
    for i in range(n):
        a.append(int(input()))
    MP(n,a)

Submission status: Wrong Answer

Solution code:
#coding:UTF-8

def MP(n,a):
    minv=a[0]
    maxv=-100000
    for i in range(1,n):
        if maxv<a[i]-minv:
            maxv=a[i]-minv
        if minv>a[i]:
            minv=a[i]    
    print(maxv)
if __name__=="__main__":
    n=int(input())
    a=[]
    for i in range(n):
        a.append(int(input()))
    MP(n,a)

Submission status: Wrong Answer

Solution code:
n=input()
min = input()
max = input()

cand = 0
flg = False
flg2 = True
for x in xrange(n-2):
    v = input()
    if max < v and flg2:
        max = v
        continue
    elif min > v:
        if max -min > cand or not flg:
            cand = max - min
            flg = True
        min = v
        flg2 = False
        continue
    
    if not flg2:
        max = v

if not flg2:
    print cand
elif cand > max -min:
    print cand
else:
    print max - min

Submission status: Wrong Answer

Solution code:
n=input()
min = input()
max = input()

cand = max - min
flg = False
flg2 = True
for x in xrange(n-2):
    v = input()
    if max < v and flg2:
        max = v
        continue
    elif min > v:
        if max -min > cand or not flg:
            cand = max - min
            flg = True
        min = v
        flg2 = False
        continue
    
    if not flg2:
        max = v

if not flg2:
    print cand
elif cand > max -min:
    print cand
else:
    print max - min

Submission status: Wrong Answer

Solution code:
n=input()
min = input()
max = input()

cand = max - min
renew = False
for x in xrange(n-2):
    v = input()
    if min > v:
        if (not renew) and (max -min > cand):
            cand = max - min
        min = v
        renew = True
        continue
    elif max < v or renew:
        max = v
        renew = False
        continue

if renew:
    print cand
elif cand > max -min:
    print cand
else:
    print max - min

Submission status: Wrong Answer

Solution code:
n=input()
min = input()
max = 0
cand=0
renew = True
for x in xrange(n-1):
    v = input()
    if min > v:
        if (not renew) and (max -min > cand):
            cand = max - min
        min = v
        renew = True
        continue
    elif max < v or renew:
        max = v
        renew = False
        continue

if renew:
    print cand
elif cand > max -min:
    print cand
else:
    print max - min

Submission status: Wrong Answer

Solution code:
n=input()
min = input()
max = 0
cand=None
renew = True

for x in xrange(n-1):
    v = input()
    if min > v:
        if (not renew) and (max -min > cand):
            cand = max - min
        if renew:
            if cand:
                if min -v > cand:
                    cand = min -v
            else:
                cand = min -v
        min = v
        renew = True
        continue
    elif max < v or renew:
        max = v
        renew = False
        continue

if renew:
    if cand:
        print cand
    else:
        print max - min
elif cand > max -min:
    print cand
else:
    print max - min

Submission status: Wrong Answer

Solution code:
n=input()
min = None
max = None
cand=None

for x in xrange(n):
    v = input()

    if min is None:
        min = v
        continue

    if min > v:
        if (cand is None) or (cand < v-min):
            cand = v-min
        min = v
        continue

    elif (max is None) or (max < v):
        max = v
        cand = max - min
        continue

print cand