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:
if __name__ == '__main__':
	n = int(input())
	lists = list()

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

	S = None
	while lists:
		mini = min(lists)
		mini_ind = lists.index(mini)

		if mini_ind + 1 == len(lists):
			if S is None:
				for i in range(n - 1):
					T = lists[i + 1] - lists[i]
					if S is None or T > S:
						S = T
				break

			else:
				break

		maxi = max(lists[mini_ind : len(lists)])
		T = maxi - mini

		if S is None or S < T:
			print(T,S)
			S = T

		lists = lists[0 : mini_ind]
		continue

	print(S)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
	n = int(input())
	lists = list()

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

	S = None
	while lists:
		mini = min(lists)
		mini_ind = lists.index(mini)

		if mini_ind + 1 == len(lists):
			if S is None:
				for i in range(n - 1):
					T = lists[i + 1] - lists[i]
					if S is None or T > S:
						S = T
				break

			else:
				break

		maxi = max(lists[mini_ind : len(lists)])
		T = maxi - mini

		if S is None or S < T:
			S = T

		lists = lists[0 : mini_ind]
		continue

	print(S)

Submission status: Wrong Answer

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

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

    return maxv

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

    return maxv

if __name__ == '__main__':

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

    ans = maximum_profit_2(n ,R)
    print(ans)

Submission status: Wrong Answer

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

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

print(maxv)

Submission status: Wrong Answer

Solution code:
b,s=-1e7,1e7
for _ in range(int(input())):
 r=int(input())
 b,s=max(b,r-s),min(s,r)
print(b)

Submission status: Wrong Answer

Solution code:
b,s=-1e9,1e9
for _ in range(int(input())):
 r=int(input())
 b,s=max(b,r-s),min(s,r)
print(b)

Submission status: Wrong Answer

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-1):
        b = nums[q]
        ns.append(b-a)
        
print(max(ns))

Submission status: Wrong Answer

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


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

ma = -10000
mi = nums[0]
for p in range(1,len(nums)):
    a = nums[p]
    if a > a-mi:
        ma = a-mi
    if a < mi:
        mi = a
    
        

    
        
print(ma)

Submission status: Wrong Answer

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


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

ma = -10000
mi = nums[0]
for p in range(1,len(nums)):
    a = nums[p]
    if a-mi > ma:
        ma = a-mi
    if a < mi:
        mi = a
    
        

    
        
print(ma)

Submission status: Wrong Answer

Solution code:
count = int(input());
data = [];
for i in range(count):
    data.append(int(input()));
def max_profit(data):
    hasMinN = False;
    minN = 0;
    current = data[0];
    maxN = data[1];

    for n in data[2:]:
        if not hasMinN:
            if n > maxN:
                maxN = n;
            elif n < current:
                hasMinN = True;
                minN = n;
        else:
            if n - minN > maxN - current:
                maxN = n;
                current = minN;
                hasMinN = False;
            elif n < minN:
                minN = n;
    return maxN - current;
print(max_profit(data));

Submission status: Wrong Answer

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

for i in range(N):
    tmp = int(input())
    list.append(tmp)

maxDiff = 0
tmpMin = 10 ** 9
tmpMax = 0
for i in range(N):
    for j in range(i+1, N):
        tmpDiff = list[j] - list[i]
        if tmpDiff > maxDiff:
            maxDiff = tmpDiff
print(maxDiff)

Submission status: Wrong Answer

Solution code:
import sys
numbers = []
for line in sys.stdin:
	numbers.append(int(line))

max = numbers[2] - numbers[1]


for i in range(1, len(numbers) - 1 ):
	for j in range(i + 1, len(numbers) - 1):
		if numbers[j] - numbers[i] > max :
			max = numbers[j] - numbers[i]
print(max)

Submission status: Wrong Answer

Solution code:
n = int(input())

before = int(input())
current = int(input())
diffMax = current - before
for i in range(n - 2):
  number = int(input())
  diff = number - current
  diffMax = max(diff, diffMax)
  current = min(current, number)
print(diffMax)

Submission status: Wrong Answer

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

for i in range(N):
    tmp = int(input())
    list.append(tmp)

maxDiff = - 10 ** 9
tmpMin = 10 ** 9
for i in range(N):
    maxDiff = max([maxDiff, list[i] - tmpMin])
    tmpMin = min([tmpMin, list[i]])
print(maxDiff)

Submission status: Wrong Answer

Solution code:
import sys
numbers = []
for line in sys.stdin:
	numbers.append(int(line))

max = numbers[2] - numbers[1]


for i in range(1, len(numbers) - 1):
	for j in range(i + 1, len(numbers)):
		if numbers[j - 1] - numbers[i] > max :
			max = numbers[j] - numbers[i]
print(max)

Submission status: Wrong Answer

Solution code:
import sys
numbers = []
for line in sys.stdin:
	numbers.append(int(line))

max = numbers[2] - numbers[1]

count = 1
while count < len(numbers) - 1:
	if numbers[count + 1] -  numbers[count] > max :
		max = numbers[count + 1] -  numbers[count]
	count += count

print(max)

Submission status: Wrong Answer

Solution code:
import sys
numbers = []
for line in sys.stdin:
	numbers.append(int(line))

max = numbers[2] - numbers[1]

count = 1

while count < len(numbers) - 1:
	if numbers[count + 1] -  numbers[count] > max :
		max = numbers[count + 1] -  numbers[count]
	count += count

print(max)

Submission status: Wrong Answer

Solution code:
import sys
numbers = []
for line in sys.stdin:
	numbers.append(int(line))

answer = numbers[2] - numbers[1]

count = 1
while count < len(numbers) - 1:
	target = max(numbers[count : ])
	if target -  numbers[count] > answer :
		answer = target -  numbers[count]
	count += count

print(answer)

Submission status: Wrong Answer

Solution code:
import sys
numbers = []
for line in sys.stdin:
	numbers.append(int(line))

answer = numbers[2] - numbers[1]
tmp_min = numbers[1]

for target in range(1, len(numbers)):
	answer =  max(numbers[target] - tmp_min ,answer)
	tmp_min = min(numbers[target] , tmp_min)
print(answer)

Submission status: Wrong Answer

Solution code:
import sys
numbers = []
for line in sys.stdin:
	numbers.append(int(line))

answer = numbers[2] - numbers[1]
tmp_min = numbers[1]
print("answer0 : "+ str(answer))


for target in range(2, len(numbers)):
	answer =  max(numbers[target] - tmp_min ,answer)
	tmp_min = min(numbers[target] , tmp_min)

print(answer)

Submission status: Wrong Answer

Solution code:
length = int(input())
minv = int(input())
maxv = int(input()) - minv
for j in range(2, length):
    hoge = int(input())
    maxv = max(maxv, hoge-minv)
    minv = min(minv, hoge)
print (maxv)

Submission status: Wrong Answer

Solution code:
length = int(input())
minv = int(input())
maxv = -20000000
for j in range(1, length):
    hoge = int(input())
    maxv = max(maxv, hoge-minv)
    minv = min(minv, hoge)
print (maxv)

Submission status: Wrong Answer

Solution code:
# coding: UTF-8
n = int(raw_input())
value_list = []
now_indx = 0
for i in range(n):
    value_list.append(int(raw_input()))
    if i == 1:
        diff =value_list[1] - value_list[0]
        now_indx = 1
    if value_list[i] >= value_list[now_indx]:
        for j in range(i):
            diff2 = value_list[i] - value_list[j]
            if diff < diff2:
                diff = diff2
                now_indx = i
print diff

Submission status: Wrong Answer

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

Solution code:
# coding: UTF-8
n = int(raw_input())
value_list = []
diff_indx1 = 0
diff_indx2 = 0
diff = None
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]:
        diff2 = value_list[i] - value_list[diff_indx2]
        if diff <= diff2:
            diff = diff2
            diff_indx1 = i
            diff_indx2 = diff_indx2
            #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: Wrong Answer

Solution code:
# coding: UTF-8
n = int(raw_input())
value_list = []
diff_indx1 = 0
diff_indx2 = 0
diff = None     #変数の初期化
for i in range(n):
    value_list.append(int(raw_input()))
    if i == 1:#　diffとdiff_indx1の初期化
        diff = value_list[1] - value_list[0]
        diff_indx1 = 1
    if value_list[i] >= value_list[diff_indx1]:#最大値の更新と最大差分の更新
        diff = value_list[i] - value_list[diff_indx2]
        diff_indx1 = i
        diff_indx2 = diff_indx2
    if value_list[diff_indx2] > value_list[i]:#最小値の更新
        diff_indx2 = i
        diff_indx1 = i
print diff

Submission status: Wrong Answer

Solution code:
init = None
diff = None
for p in range(int(input())):
    v = int(input())
    if init is None:
        init = v
        continue
    if diff is None:
        diff = v - init
        continue
        
    if v - init > diff:
        diff = v - init
    if init > v:
        init = v

print(diff)

Submission status: Wrong Answer

Solution code:
# coding: UTF-8
n = int(raw_input())
value_list = []
diff_indx1 = 0
diff_indx2 = 0
diff = None
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]:
        diff2 = value_list[i] - value_list[diff_indx2]
        #print("{}:{} - {}:{} = {}@1").format(diff_indx1,value_list[diff_indx1],diff_indx2,value_list[diff_indx2],diff2)
        if diff <= diff2:
            diff = diff2
            diff_indx1 = i
            diff_indx2 = diff_indx2
            #print("{}:{} - {}:{} = {}@2").format(diff_indx1,value_list[diff_indx1],diff_indx2,value_list[diff_indx2],diff)
    if value_list[diff_indx2] > value_list[i]:
        diff_indx2 = i
        diff_indx1 = i
        #print("{}:{}").format(i,value_list[i])
print diff

Submission status: Wrong Answer

Solution code:
#import time

N = int(input())
datas = [int(input()) for _ in range(N)]
#start = time.time()
now_max = max(datas[1:])
diff = now_max - datas[0]

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

print(diff)
#print('time :',time.time()-start)

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
gain = -999999999
max = 1000000000
for i in range(n):
    new = int(raw_input())
    if max < new:
        if gain < max - new:
            gain =  max - new
    else:
        max = new
print gain

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
gain = -999999999
max = 1000000000
for i in range(n):
    new = int(raw_input())
    if max > new:
        max = new
    if gain < new - max:
        gain =  new - max
print gain

Submission status: Wrong Answer

Solution code:
n = int(input())
gain = -999999999
mini = 1000000000
for i in range(n):
    new = int(input())
    if mini > new:
        mini = new
    if gain < new - mini:
        gain = new - mini
print (gain)

Submission status: Wrong Answer

Solution code:
n = int(input())
gain = -999999999
mini = 1000000000
for i in range(n):
    new = int(input())
    gain = max(gain, new - mini)
    mini = min(mini, new)
print (gain)

Submission status: Wrong Answer

Solution code:
N = int(input())
datas = [int(input()) for _ in range(N)]
now_max = max(datas[1:])
max_index = datas[::-1].index(now_max)
_min = min(datas)
min_index = datas.index(_min)

if max_index > min_index:
    diff = now_max - _min
else:
    diff = now_max - datas[0]
    
    for i in range(1,N-1):
        if i == max_index:
            now_max = max(datas[i+1:])
            max_index = datas.index(now_max,i+1)
        new_diff = now_max - datas[i]
        if diff < new_diff:
            diff = new_diff

print(diff)

Submission status: Wrong Answer

Solution code:
N = int(input())
datas = [int(input()) for _ in range(N)]
now_max = max(datas[1:])
max_index = (N-1) - datas[::-1].index(now_max)
_min = min(datas)
min_index = datas.index(_min)

if max_index > min_index:
    diff = now_max - _min
    print('max',now_max,'max_i',max_index)
    print('min',_min,'min_i',min_index)
else:
    diff = now_max - datas[0]
    
    for i in range(1,N-1):
        if i == max_index:
            now_max = max(datas[i+1:])
            max_index = datas.index(now_max,i+1)
        new_diff = now_max - datas[i]
        if diff < new_diff:
            diff = new_diff

print(diff)

Submission status: Wrong Answer

Solution code:
n = int(input())
minR = int(input())
maxR = int(input())-minR
for i in range(n-2):
    po = int(input())
    maxR = max(maxR,po-minR)
    minR = min(minR,po)
print(maxR)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
def inpl(): return tuple(map(int, input().split()))
N = int(input())

def main(N):
    min_ = int(input())
    max_ = int(input())
    res = -2 * 10**9
    obs = True
    for _ in range(N-2):
        r = int(input())
        if r > max_:
            max_ = r
            obs = True
            continue
        elif r < min_:
            if obs:
                res = max(res, max_ - min_)
            min_ = r
            obs = False
            max_ = 0
    if obs:
        res = max(res, max_ - min_)

    return res
        
print(main(N))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
def inpl(): return tuple(map(int, input().split()))
N = int(input())

def main(N):
    min_ = int(input())
    max_ = int(input())
    res = max_ - min_
    obs = True
    
    if max_ < min_:
        min_ = max_
        max_ = 0
        obs = False

    for _ in range(N-2):
        r = int(input())
        if r > max_:
            max_ = r
            obs = True
            continue
        elif r < min_:
            if obs:
                res = max(res, max_ - min_)
            min_ = r
            obs = False
            max_ = 0
    if obs:
        res = max(res, max_ - min_)

    return res
        
print(main(N))

Submission status: Wrong Answer

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 r_i in r:
    if r_temp_min <= r_i:
        continue
    ans = ans - r_i + r_temp_min
    r_temp_min = r_i

print(ans)

Submission status: Wrong Answer

Solution code:
def maximum_profit(n):
    maxv = min(n) - max(n)
    for i in range(len(n)):
        m = max(n[i+1:]) if i+1 < len(n) else 0
        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: Wrong Answer

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

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

print(max_diff)

Submission status: Wrong Answer

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

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

print(max_diff)

Submission status: Wrong Answer

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

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

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

max_diff = -10000000
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: Wrong Answer

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

min_diff = nums[0]
max_diff = nums[1] - nums[0]
for i in range(len(nums)):
    if max_diff < nums[i] - min_diff:
        max_diff = nums[i] - min_diff
    if min_diff > nums[i]:
        min_diff = nums[i]

print(max_diff)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

maxv = -200000000
minv = R[0]

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

print(maxv)

Submission status: Wrong Answer

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

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

    i=0
    j=1
    pm=a[1]-a[0]
    for k in range(2, n):
        if a[k]>a[j]:
            j=k
            p=a[k]-a[i]
            pm=max(p,pm)
        else:
            i=k
            j=k
    print(pm)
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

    i=0
    j=1
    p=a[j]-a[i]
    for k in range(2, n):
        if a[k]>a[j]:
            j=k
            p=max(p,a[j]-a[i])
        else:
            i=k
            j=k
    print(p)
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

    i=j=0
    p=a[1]-a[0]
    for k in range(1, n):
        #print('i=%d j=%d k=%d p=%d' % (i,j,k,p))
        if a[k]>a[j]:
            j=k
            p=max(p,a[j]-a[i])
        else:
            i=j=k
    print(p)
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

    pmax=a[1]-a[0]
    for k in range(1, n-1):
        p=max(a[k+1:])-a[k] 
        if p > pmax:
            pmax=p

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

Submission status: Wrong Answer

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)]

Submission status: Wrong Answer

Solution code:
l = []
for _ in range(int(input())):
  l += [int(input())]
mx = max(l)
i = l.index(mx)
while i == 0:
  t = l[i+1:]
  mx = max(t)
  i = l.index(mx)
  if len(t) == 1: break
print(mx - min(l[:i]))

Submission status: Wrong Answer

Solution code:
n = int(input())
min_v = int(input())
ans = 1 - min_v
for i in range(1, n-1):
    j = int(input())
    ans = max(ans, j - min_v)
    min_v = min(min_v, j)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

maxv =  int(-20000000)
minv = int(r[0])

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

print(maxv)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

maxv =  int(-20000000)
minv = int(r[0])

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

print(maxv)

Submission status: Wrong Answer

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

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

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

print(ans)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

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

maxv = -10e10
minv = 10e10

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

print(maxv)

Submission status: Wrong Answer

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

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

maxv = -10e10
minv = a[0]

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

print(maxv)

Submission status: Wrong Answer

Solution code:
n = int(input())

maxv =  int(-20000000)
minv = 10**12

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

print(maxv)

Submission status: Wrong Answer

Solution code:
n = int(input())

maxv =  int(-20000000)
minv = 10**12

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

print(maxv)

Submission status: Wrong Answer

Solution code:
n = int(input())

maxv = 10**18
minv = 10**18

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

print(maxv)

Submission status: Wrong Answer

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

    
print(maximum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys

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

maxv = - sys.maxsize - 1

for i in values:
    for j in values:
        val = i - j
        if maxv < val:
            maxv = val

print(maxv)

Submission status: Wrong Answer

Solution code:
import sys

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

maxv = - sys.maxsize - 1
minv = values[0]

for c, value in enumerate(values):
    maxv = max(maxv, value - minv)
    minv = min(minv, value)         # 今までの最小値を保持(自分と自分を比較しない様に、最大値の評価後に計算)

print(maxv)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for val in enumerate(values):
    pass
print(maxv)

Submission status: Wrong Answer

Solution code:
n = int(input())
x = []
for i in range(n):
    x.append(int(input()))
m = 0
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: Wrong Answer

Solution code:
n = int(input())
x = []
for i in range(n):
    x.append(int(input()))
m = -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: Wrong Answer

Solution code:
n = int(input())
x = []
for i in range(n):
    x.append(int(input()))
m = float("inf")
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: Wrong Answer

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

Submission status: Wrong Answer

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

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

B = A[:-1]
mini = min(B)
min_idx = B.index(mini)
C = A[min_idx+1:]
maxi = max(C)

print(maxi - mini)

Submission status: Wrong Answer

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

for i in range(n): A.append(float(input()))

B = A[:-1]
mini = min(B)
min_idx = B.index(mini)
C = A[min_idx+1:]
maxi = max(C)

print(maxi - mini)

Submission status: Wrong Answer

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

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

B = A[:-1]
mini = min(B)
min_idx = B.index(mini)
C = A[min_idx+1:]
maxi = max(C)

print(maxi - mini)

Submission status: Wrong Answer

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

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

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

print(maxv)

Submission status: Wrong Answer

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

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

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

print(maxv, minv)

Submission status: Wrong Answer

Solution code:
import sys

values = [int(input()) for i in range(int(input()))]
maxv = - sys.maxsize - 1
minv = values[0]

for val in enumerate(values):
    pass
print(maxv)

Submission status: Wrong Answer

Solution code:
import sys

values = [int(input()) for i in range(int(input()))]
maxv = - sys.maxsize - 1
minv = values[0]

for val in enumerate(values):
    mine = 1
print(maxv)

Submission status: Wrong Answer

Solution code:
import sys

values = [int(input()) for i in range(int(input()))]
maxv = - sys.maxsize - 1
minv = values[0]

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

Submission status: Wrong Answer

Solution code:
import sys

values = [int(input()) for i in range(int(input()))]
maxv = - sys.maxsize - 1
minv = values[0]

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