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()
min = None
max = None
cand=None

for x in xrange(n):
    v = input()
   
    # print "#### %s %s %s %s" % (str(max), str(min), str(cand), str(v))

    if min is None:
        min = v
        # print "min is None"
        continue

    if min > v:
        # print "min > v"
        if (cand is None) or (cand < v-min):
            # print "cand None"
            cand = v-min
        min = v
        max = None
        continue

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

print cand

Submission status: Wrong Answer

Solution code:
n = int(input())
R = []
for i in range(n):
    R.append(int(input()))
r = sorted(R)
maximum_profit = r[n-1] - r[0]
print(maximum_profit)

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
nums = []

for i in range(N):
    nums.append(int(raw_input()))

m = -100000000

for i in range(len(nums)):
    for j in range(0, i):
        if m < nums[i] - nums[j]:
            m = nums[i] - nums[j]

print(m)

Submission status: Wrong Answer

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

interest = b - a
min = min(a,b)
for i in range(n-2):
    f = int(input())
    if f - min > interest:
        interest = f - min
    else:
        f < min
        min = f
print(interest)

Submission status: Wrong Answer

Solution code:
N = input("number")
nums = []
for i in range(N):
     nums.append(input())

max = nums[0]
min = nums[0]

for num in nums:
     if num > max:
          max = num
     if num < min:
          min = num

print max - min

Submission status: Wrong Answer

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

max = nums[0]
min = nums[0]

for num in nums:
     if num > max:
          max = num
     if num < min:
          min = num

print max - min

Submission status: Wrong Answer

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

profit = nums[1] - nums[0]
for a in range(N-1):
     for b in range(a):
          if (nums[a] - nums[b]) > profit:
               profit = nums[a] - nums[b]

print profit

Submission status: Wrong Answer

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

profit = nums[1] - nums[0]
min = nums[0]
for a in range(N):
     if nums[a] < min:
               min = nums[a]
     if nums[a] - min > profit:
          profit = nums[a] - min

print profit

Submission status: Wrong Answer

Solution code:
N = input()
R = [int(raw_input()) for _ in xrange(N)]
S = [0 for i in xrange(N)]
S[N-1] = R[N-1]
for i in xrange(N-2, -1, -1):
    S[i] = max(R[i], S[i+1])
ans = float('-inf')
for i in xrange(N-1):
    ans = max(ans, S[i+1]-R[i])

Submission status: Wrong Answer

Solution code:
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_D
#?????§??????
#??????????????????????????°???????????????????????¢?????´?????????????????????
def get_maximum_profit(value_list):
    minv = pow(10,9)
    profit = -minv
    for i in range(1, len(value_list)):
        profit = max(profit, value_list[i] - minv) 
        minv = min(minv, value_list[i])
    return profit

def main():
    n_list = int(input())
    target_list = [int(input()) for i in range(n_list)]
    print(get_maximum_profit(target_list))
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_D
#?????§??????
#??????????????????????????°???????????????????????¢?????´?????????????????????
def get_maximum_profit(value_list, n_list):
    minv = pow(10,9)
    profit = -minv
    for v in value_list:
        profit = max(profit, v - minv) 
        minv = min(minv, v)
    return profit

def main():
    n_list = int(input())
    target_list = [int(input()) for i in range(n_list)]
    print(get_maximum_profit(target_list, n_list))
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:


def solve():
    n = int(raw_input())
    R = []

    for i in xrange(n):
        R.append(int(raw_input()))

    #for i in xrange(n):
    #    print R[i]

    max_profit = 0
    for i in xrange(n):
        for j in xrange(i + 1, n):
            if abs(R[j] - R[i]) > max_profit:
                max_profit = R[j] - R[i]


    print max_profit


if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
import sys

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

Submission status: Wrong Answer

Solution code:
import sys

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

max=a[0]
min=a[1]

Submission status: Wrong Answer

Solution code:
import sys

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

max=a[0]
min=a[1]

for b in a:
 if a[b] <= min:
  min=a[b]
 if a[b] >= max:
  max=a[b]

print(max-min)

Submission status: Wrong Answer

Solution code:
import sys

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

min=a[0]

for b in a:
 if a[b]-min >= max:
  max=a[b]-min
 if a[b] <= min:
  min=a[b]

print(max)

Submission status: Wrong Answer

Solution code:
import sys

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

min=a[0]
max=0

for b in a:
 if a[b]-min >= max:
  max=a[b]-min
 if a[b] <= min:
  min=a[b]

print(max)

Submission status: Wrong Answer

Solution code:
import sys

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

min=a[0]
max=-10**9

for b in a:
 if a[b]-min >= max:
  max=a[b]-min
 if a[b] <= min:
  min=a[b]

print(max)

Submission status: Wrong Answer

Solution code:
import sys

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

min=a[0]
max=-1*10**9

for b in a:
 if a[b]-min >= max:
  max=a[b]-min
 if a[b] <= min:
  min=a[b]

print(max)

Submission status: Wrong Answer

Solution code:
n = int(raw_input())

R = [0 for i in range(n)]

ans = 1 - 10**9
for i in range(n):
    R[i] = int(raw_input())
    if i == 0:
        min_R = R[0]
        continue
    if min_R < R[i] and ans < R[i]-min_R:
        ans = R[i] - min_R
    elif min_R > R[i]:
        if ans < R[i]-min_R:
            ans = R[i] - min_R
        min_R = R[i]
        
print ans

Submission status: Wrong Answer

Solution code:
n = int(raw_input())

R = [0 for i in range(n)]

ans = 1 - 10**9
for i in range(n):
    R[i] = int(raw_input())
    if i == 0:
        min_R = R[0]
        continue
    if min_R < R[i]:
        if ans < R[i]-min_R:
            ans = R[i] - min_R
    elif min_R > R[i]:
        if ans < R[i]-min_R:
            ans = R[i] - min_R
        min_R = R[i]
    else:
        ans = 0
        
print ans

Submission status: Wrong Answer

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

for i in range(n):
  x = int(input())

  diff = x - prev
  prev = x

  if i == 0: continue

  if diff * p[i - 1] > 0:
    p[i] = p[i - 1] + diff
  else:
    p[i] = diff

print(max(p[1:]))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
6
5
3
1
3
4
3

output:
3
"""

import sys


def solve():
    # write your code here
    max_profit = 0
    min_stock = prices[0]
    for price in prices[1:]:
        max_profit = max(max_profit, price - min_stock)
        min_stock = min(min_stock, price)
    return max_profit if max_profit else -1


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    p_num = int(_input[0])
    prices = list(map(int, _input[1:]))
    print(solve())

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
6
5
3
1
3
4
3

output:
3
"""

import sys


def solve():
    # write your code here
    max_profit = -1
    min_stock = prices[0]
    for price in prices[1:]:
        max_profit = max(max_profit, price - min_stock)
        min_stock = min(min_stock, price)
    return max_profit


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    p_num = int(_input[0])
    prices = list(map(int, _input[1:]))
    print(solve())

Submission status: Wrong Answer

Solution code:

num = int(input())
num_list = [int(input()) for x in range(num)]
max_difference = -9999999

for i in range(num):
    for j in range(i+1, num):
        difference = num_list[j] - num_list[i]
        if max_difference < difference:
            max_difference = difference

print(max_difference)

Submission status: Wrong Answer

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

def maximum_profit(price_list):
    max = -200000
    for x in range(len(price_list)-1):
        for y in range(x+1, len(price_list)):
            if max < price_list[y] - price_list[x]:
                max = price_list[y] - price_list[x]
    return max

input_num = int(input())
price_list = list()
for i in range(input_num):
    input_price = int(input())
    price_list.append(input_price)
print(maximum_profit(price_list))

Submission status: Wrong Answer

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

def maximum_profit(price_list):
    max = -300000
    for x in range(len(price_list)-1):
        for y in range(x+1, len(price_list)):
            if max < price_list[y] - price_list[x]:
                max = price_list[y] - price_list[x]
    return max

input_num = int(input())
price_list = list()
for i in range(input_num):
    input_price = int(input())
    price_list.append(input_price)
print(maximum_profit(price_list))

Submission status: Wrong Answer

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

def maximum_profit(price_list):
    max = price_list[1] - price_list[0]
    min = price_list[0]
    for i in range(len(price_list)-1):
        if max < price_list[i] - min:
            max = price_list[i] - min
        if min > price_list[i]:
            min = price_list[i]
    return max

input_num = int(input())
price_list = list()
for i in range(input_num):
    input_price = int(input())
    price_list.append(input_price)
print(maximum_profit(price_list))

Submission status: Wrong Answer

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

def maximum_profit(price_list):
    max = price_list[1] - price_list[0]
    min = price_list[0]
    for i in range(len(price_list)):
        if max < price_list[i] - min:
            max = price_list[i] - min
        if min > price_list[i]:
            min = price_list[i]
    return max

input_num = int(input())
price_list = list()
for i in range(input_num):
    input_price = int(input())
    price_list.append(input_price)
print(maximum_profit(price_list))

Submission status: Wrong Answer

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

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

print(candidate[0])

Submission status: Wrong Answer

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

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

print(candidate[0])

Submission status: Wrong Answer

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

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

print(candidate[0])

Submission status: Wrong Answer

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

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

print(candidate[0])

Submission status: Wrong Answer

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

candidate = [-10**8]
for i in range(len(stack) - 1):
    for r1, r2 in zip(stack[::1], stack[i::1]):
        candidate.append(r2 - r1)
    candidate = [max(candidate)]

print(candidate[0])

Submission status: Wrong Answer

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

candidate = [-10**8]
for i in range(1, len(stack)):
    for r1, r2 in zip(stack[::1], stack[i::1]):
        candidate.append(r2 - r1)
    candidate = [max(candidate)]

print(candidate[0])

Submission status: Wrong Answer

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

candidate = [-float('inf')]
for i in range(1, len(stack) // 2 + 1):
    for r1, r2 in zip(stack[::1], stack[i::1]):
        if r2 - r1 > 0:
            candidate.append(r2 - r1)
    for r1, r2 in zip(stack[::1], stack[len(stack) - i::1]):
        if r2 - r1 > 0:
            candidate.append(r2 - r1)
    candidate = [max(candidate)]

print(candidate[0])

Submission status: Wrong Answer

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


def maximum_profit(profits):
    max_v = profits[1] - profits[0]

    for j in range(1, len(profits)):
        for i in range(0, j-1):
            max_v = max(profits[j] - profits[i], max_v)

    print(max_v)


if __name__ == '__main__':
    maximum_profit([5, 3, 1, 3, 4, 3])

Submission status: Wrong Answer

Solution code:
a,b=-1e3,1e3
for _ in range(int(input())):
    c=int(input())
    a,b=max(a,c-b),min(b,c)
print(a)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    price = [int(input()) for i in range(N)]
    minv = price[0]
    maxv = -1
    for p in price:
        minv = min(minv, p)
        maxv = max(maxv, p-minv)
    print(maxv)



if __name__ == "__main__":
    import os
    import sys
    if len(sys.argv) > 1:
        if sys.argv[1] == "-d":
            fd = os.open("input.txt", os.O_RDONLY)
            os.dup2(fd, sys.stdin.fileno())
            main()
    else:
        main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    price = [int(input()) for i in range(N)]
    minv = price[0]
    maxv = -float("inf")
    for p in price:
        minv = min(minv, p)
        maxv = max(maxv, p-minv)
    print(maxv)



if __name__ == "__main__":
    import os
    import sys
    if len(sys.argv) > 1:
        if sys.argv[1] == "-d":
            fd = os.open("input.txt", os.O_RDONLY)
            os.dup2(fd, sys.stdin.fileno())
            main()
    else:
        main()

Submission status: Wrong Answer

Solution code:
N = int(input())
M = -1000000000
L = int(input())
for i in range(2,N):
    C = int(input())
    M = max(C - L, M)
    L = min(C, L)
print(M)

Submission status: Wrong Answer

Solution code:
def profit(list):
    syo = min(list[:len(list)-1])
    dai = max(list[min(list):])
    return dai - syo

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

max_profit = profit(list)
print(max_profit)

Submission status: Wrong Answer

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

min_v = 1000000000
max_p = -1000000000
for i in range(n):
    max_p = max(max_p,r[i]-min_v)
    min_v = min(min_v,r[i])
print(max_p)

Submission status: Wrong Answer

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

min_v = 1000000000
max_p = -1000000000
for i in range(1,n):
    max_p = max(max_p,r[i]-min_v)
    min_v = min(min_v,r[i])
print(max_p)

Submission status: Wrong Answer

Solution code:
def profit(list):
    syo = min(list[:len(list)-1])
    dai = max(list[min(list):])
    maxi = max(list[1:])
    print(max(list[1:]))
    minn = min(list[maxi:])
    if dai - syo > maxi - minn:
        return dai - syo
    else:
        return maxi - minn

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

max_profit = profit(list)
print(max_profit)

Submission status: Wrong Answer

Solution code:
def profit(list):
    maxi = -1
    minn = -1
    syo = min(list[:len(list)-1])
    dai = max(list[min(list):])
    newlist = list[list.index(dai):]
    # print(newlist)
    if len(newlist) > 1:
        minn = min(list[:len(newlist)-1])
        maxi = max(list[min(newlist):])
    # print(syo,dai,maxi,minn)
    if maxi == -1 and minn == -1:
        return dai - syo
    else:
        if dai - syo > maxi - minn:
            return dai - syo
        else:
            return maxi - minn

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

max_profit = profit(list)
print(max_profit)

Submission status: Wrong Answer

Solution code:
from sys import stdin
n = int(input())
r=[int(input()) for i in range(n)]
rv = r[::-1][:-1]

print(max([r_j - r_i for j,r_j in enumerate(rv) for r_i in r[:-j]]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())

R = []

for i in range(0,n):
    R.insert(i,int(input()))


MIN = min(R[:n-1])

m_index = R.index(MIN)

MAX = max(R[m_index+1:])

if MAX < MIN:
    MAX = min(R[m_index:])

print(MAX - MIN)

Submission status: Wrong Answer

Solution code:
n = int(input())

R = []

for i in range(0,n):
    R.insert(i, int(input()))

m = min(R[0:2])
MAX = R[1] - R[0]
for r in range(1, n-1):
    if(R[r] < m):
        m = R[r]
    MAX = R[r+1] - m

print(MAX)

Submission status: Wrong Answer

Solution code:
n = int(input())

R = []

for i in range(0,n):
    R.insert(i, int(input()))

m = min(R[0:2])
MAX = R[1] - R[0]
for r in range(1, n):
    if(R[r-1] < m):
        m = R[r-1]
    MAX2 = R[r] - m
    if(MAX2 > MAX):
        MAX = MAX2

print(MAX)

Submission status: Wrong Answer

Solution code:
n = int(input())
R = [int(input()) for i in range(n)]
profit= R[1] - R[0]
mn = min(R[0],R[1])
for i in R:
    if profit < i - mn:
        profit = i - mn
        if 0 > i - mn:
            mn = i
    elif mn > i:
        mn = i

print(profit)

Submission status: Wrong Answer

Solution code:
n = int(input())
R = [int(input()) for i in range(n)]
profit= R[1] - R[0]
mn = min(R[0],R[1])
for i in R:
    if profit < i - mn:
        profit = i - mn
        if 0 < i - mn:
            mn = i
    elif mn > i:
        mn = i

print(profit)

Submission status: Wrong Answer

Solution code:
n = int(input())
R = [int(input()) for i in range(n)]
profit= R[1] - R[0]
mn = R[0]
for i in R:
    if profit < i - mn:
        profit = i - mn
        if 0 > i - mn:
            mn = i
    elif mn > i:
        mn = i

print(profit)

Submission status: Wrong Answer

Solution code:
n = int(input())
R = [int(input()) for i in range(n)]
profit= R[1] - R[0]
mn = R[1]
for i in R:
    if profit < i - mn:
        profit = i - mn
        if 0 > i - mn:
            mn = i
    elif mn > i:
        mn = i

print(profit)

Submission status: Wrong Answer

Solution code:
n = int(input())
R = [int(input()) for i in range(n)]
profit= R[1] - R[0]
mn = R[0]
R.pop(0)
R.pop(1)
for i in R:
    if profit < i - mn:
        profit = i - mn
        if 0 > i - mn:
            mn = i
    elif mn > i:
        mn = i

print(profit)

Submission status: Wrong Answer

Solution code:
N = int(input())
max_p = -114514
min_v = int(input())
for i in range(1, N):
    R = int(input())
    max_p = max(R - min_v, max_p)
    min_v = min(R, min_v)

print(max_p)

Submission status: Wrong Answer

Solution code:
N = int(input())
max_p = -114514810
min_v = int(input())
for i in range(1, N):
    R = int(input())
    max_p = max(R - min_v, max_p)
    min_v = min(R, min_v)

print(max_p)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
num = int(raw_input())
numbers = []
counter = 0
while counter < num:
    numbers.append(int(raw_input()))
    counter += 1

maximum = -99999

for index, num in enumerate(numbers[:-1]):
    max_diff = max(numbers[index+1:]) - num
    if max_diff > maximum:
        maximum = max_diff

print maximum

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
num = int(raw_input())
numbers = []
counter = 0
while counter < num:
    numbers.append(int(raw_input()))
    counter += 1

maximum = None

for index, num in enumerate(numbers[:-1]):
    print numbers[index+1:]
    max_diff = max(numbers[index+1:]) - num
    if max_diff > maximum:
        maximum = max_diff

print maximum

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
num = int(raw_input())
a = int(raw_input())
b = int(raw_input())
diff = b - a
pre_min = a

counter = 2
while counter < num:
    current_num = int(raw_input())
    if diff < current_num - pre_min:
        diff = current_num - pre_min
    if pre_min > current_num:
        pre_min = current_num
    counter += 1

print diff

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
num = int(raw_input())
a = int(raw_input())
b = int(raw_input())
diff = b - a
pre_min = min(a,b)

counter = 2
while counter < num:
    current_num = int(raw_input())
    print current_num, pre_min
    if diff < current_num - pre_min:
        diff = current_num - pre_min
    if pre_min > current_num:
        pre_min = current_num
    counter += 1

print diff

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Here your code !
prof = 0
d = int(input())
li =[int(input()) for i in range(d)]
max = 0
while len(li)>1:
    for i in range(len(li)):
        if li[i]-li[0]>max:
            max= li[i]-li[0]
    li=li[1:]
print(max)

Submission status: Wrong Answer

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

if __name__ == '__main__':
	n = input()
	R = []

	for i in xrange(n):
		R.append(input())
	maxv = -20000000000
	minv = R[0]

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

	print maxv

Submission status: Wrong Answer

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


res =nums[1] - nums[0]
while len(nums) != 0:
    if nums.index(max(nums)) > nums.index(min(nums)):
        res = max(nums) - min(nums)
        break
    else:
        nums.remove(max(nums))

print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

x = l.index(max(l))
y = l.index(min(l))

if x == 0:
    lx = l[1:]
    x2 = lx.index(max(lx))
    if x2 == 0:
        a = lx[x2] - l[x]
    else:
        lx_max = lx[0:x2]
        a = lx[x2] - min(lx_max)
else:
    l_max = l[0:x]
    a = l[x] - min(l_max)

if y == n - 1:
    ly = l[:n - 1]
    y2 = ly.index(min(ly))
    if y2 == n - 2:
        b = l[y] - ly[y2]
    else:
        ly_min = ly[y2 + 1:]
        b = max(ly_min) - ly[y2]
else:
    l_min = l[y + 1:]
    b = max(l_min) - l[y]

print(max(a, b))

Submission status: Wrong Answer

Solution code:
n = int(input())
r_first = int(input())
max_r = r_first
min_r = r_first

for _ in range(n - 1):
    r = int(input())
    if r > max_r:
        max_r = r
    if r < min_r:
        min_r = r

ans = max_r - min_r

print(ans)

Submission status: Wrong Answer

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

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

ans = R[1] - R[0]
min_R = R[0]

for r in R:
    min_R = min(min_R, r)
    ans   = max(ans, r - min_R)
print(ans)

Submission status: Wrong Answer

Solution code:
times = int(input())
element = []

for i in range(times):
    element.append(int(input()))

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

print(maxv)

Submission status: Wrong Answer

Solution code:
n = int(input())

min = float('inf')

max_diff = -float('inf')

for _ in range(n-1):
    i = int(input())

    if max_diff < i - min:
        max_diff = i - min

    if i < min:
        min = i

print(max_diff)

Submission status: Wrong Answer

Solution code:
n = int(input())
r_min = int(input())
r_t = int(input())
g_max = r_t - r_min

for _ in range(n - 2):
    r_t = int(input())
    g_max = max(r_t, r_min)
    r_min = min(r_t, r_min)
print(g_max)

Submission status: Wrong Answer

Solution code:
n = int(input())
r_min = int(input())
r_t = int(input())
g_max = r_t - r_min
r_min = min(r_t, r_min)

for _ in range(n - 2):
    r_t = int(input())
    g_max = max(r_t, r_min)
    r_min = min(r_t, r_min)
print(g_max)

Submission status: Wrong Answer

Solution code:
import sys

def get_maximum_profit():
    element_number = int(input())
    v0 = int(input())
    v1 = int(input())

    min_v = v0
    max_profit = v1-v0

    for i in range(element_number-2):
        v = int(input())
        min_v = min(min_v, v)
        max_profit = max(max_profit, v-min_v)

    print(max_profit)

if __name__ == '__main__':
    get_maximum_profit()

Submission status: Wrong Answer

Solution code:
import sys

def get_maximum_profit():
    element_number = int(input())
    v0 = int(input())
    v1 = int(input())

    min_v = min(v0, v1)
    max_profit = v1-v0

    for i in range(element_number-2):
        v = int(input())
        min_v = min(min_v, v)
        max_profit = max(max_profit, v-min_v)

    print(max_profit)

if __name__ == '__main__':
    get_maximum_profit()

Submission status: Wrong Answer

Solution code:
import sys

def get_maximum_profit():
    element_number = int(input())
    v0 = int(input())
    v1 = int(input())

    min_v = min(v0, v1)
    max_profit = v1-v0

    for i in range(element_number-2):
        v = int(input())
        max_profit = max(max_profit, v-min_v)
        min_v = min(min_v, v)
        print(min_v, max_profit)

    print(max_profit)

if __name__ == '__main__':
    get_maximum_profit()

Submission status: Wrong Answer

Solution code:
import sys

def get_maximum_profit():
    element_number = int(input())
    v0 = int(input())
    v1 = int(input())

    min_v = min(v0, v1)
    max_profit = v1-v0

    for i in range(element_number-2):
        v = int(input())
        min_v = min(min_v, v)
        max_profit = max(max_profit, v-min_v)
        print(min_v, max_profit)

    print(max_profit)

if __name__ == '__main__':
    get_maximum_profit()

Submission status: Wrong Answer

Solution code:
import sys

def get_maximum_profit():
    element_number = int(input())
    v0 = int(input())
    v1 = int(input())

    min_v = min(v0, v1)
    max_profit = v1-v0

    for i in range(element_number-2):
        v = int(input())
        max_profit = max(max_profit, v-min_v)
        min_v = min(min_v, v)
        print(min_v, max_profit)

if __name__ == '__main__':
    get_maximum_profit()

Submission status: Wrong Answer

Solution code:
n=int(input())
f=int(input())
min=f
max_num=f
max_dif=0
for i in range(n-1):
    x=int(input())
    if x>max_num:
        max_num = x
        if abs(max_dif) < abs(x-min):
            max_dif = x-min
    elif x<min:
        min = x
        max_num=1
print(max_dif)

Submission status: Wrong Answer

Solution code:
n=int(input())
f=int(input())
min=f
max_num=f
max_dif=-1*(10**9)
for i in range(n-1):
    x=int(input())
    if x>max_num:
        max_num = x
        if max_dif < x-min:
            max_dif = x-min
    elif x<min:
        min = x
        max_num=1
print(max_dif)

Submission status: Wrong Answer

Solution code:
n=int(input())
min=10**9
max_num=1
max_dif=-1*(10**9)
for i in range(n):
    x=int(input())
    if x>max_num:
        max_num = x
        if max_dif < x-min:
            max_dif = x-min
    if x<min:
        min = x
        max_num=1
print(max_dif)

Submission status: Wrong Answer

Solution code:
n=int(input())
min=10**9
max_num=1
max_dif=-1*(10**9)
for i in range(n):
    x=int(input())
    if x>max_num:
        max_num = x
        if max_dif < x-min:
            max_dif = x-min
    elif x<min:
        min = x
        max_num=1
print(max_dif)

Submission status: Wrong Answer

Solution code:
n=int(input())
min=10**9
max_num=1
max_dif=-1*(10**9)
for i in range(n):
    x=int(input())
    if x<min:
        min = x
        max_num=1
    if x>max_num:
        max_num = x
        if max_dif < max_num-min:
            max_dif = max_num-min
print(max_dif)

Submission status: Wrong Answer

Solution code:
n=int(input())
min=10**9
max_num=1
max_dif=-1*(10**9)
for i in range(n):
    x=int(input())
    if x<min:
        min = x
        max_num=1
        continue
    if x>max_num:
        max_num = x
        if max_dif < max_num-min:
            max_dif = max_num-min
print(max_dif)

Submission status: Wrong Answer

Solution code:
n=int(input())
min=10**9
max_num=1
max_dif=-1*(10**9)
for i in range(n):
    x=int(input())
    if x>max_num:
        max_num = x
        if max_dif < max_num-min:
            max_dif = max_num-min
    if x<min:
        min = x
        max_num=1
print(max_dif)

Submission status: Wrong Answer

Solution code:
#ALDS1_1_D Maximum Profit
n=int(input())
A=[]
max_dif=-1*10**9
for i in range(n):
    A.append(int(input()))
min=A[0]
for i in range(n-1):
    if(A[i+1]-min>max_dif):
        max_dif=A[i+1]
    if(min>A[i+1]):
        min=A[i+1]
print(max_dif)

Submission status: Wrong Answer

Solution code:

total_diff = 0
maxi = 0
mini = 10**9 *2 

n = int(raw_input())

for y in xrange(n):
	x = int(raw_input())
	if (mini > x) :
		mini = x
		maxi = x
		diff = 0
	elif maxi < x:
		maxi = x
		diff = maxi - mini 
		total_diff = max(total_diff, diff)	

if total_diff == 0 : total_diff = -1
print total_diff

Submission status: Wrong Answer

Solution code:

total_diff = 0
maxi = 0
mini = 10**9 *2 
prof = 0

n = int(raw_input())

for y in xrange(n):
	x = int(raw_input())
	if (mini > x) :
		if mini < 10**9*2 : prof = 1
		mini = x
		maxi = x
		diff = 0
	elif maxi < x:
		maxi = x
		diff = maxi - mini
		prof = 1
		total_diff = max(total_diff, diff)	

if total_diff == 0 : 
	if prof == 1:
		total_diff = -1
print total_diff

Submission status: Wrong Answer

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

def main():
    n , data = input_data()
    vMax = float('-inf')
    vMin = data.pop()

    for Rj in data:
        if vMax < Rj - vMin:
            vMax = Rj - vMin
        if vMin > Rj:
            vMin = Rj

    print(vMax)

def input_data():
    n = int(input())
    lst = [int(input()) for i in range(n)]
    return (n , lst)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

maxR = R[0]
minR = R[0]
maxB = 0
for i in range(1,n):
 if R[i] < minR:
  minR = R[i]
  maxR = R[i]
 elif minR <= R[i] and R[i] <= maxR:
  continue
 else:
  maxR = R[i]
  if maxR - minR > maxB:
   maxB = maxR - minR

print(str(maxB))

Submission status: Wrong Answer

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

maxR = R[1]
minR = R[0]
maxB = R[1] - R[0]
for i in range(1,n):
 if R[i] < minR:
  minR = R[i]
  maxR = R[i]
 elif minR <= R[i] and R[i] <= maxR:
  continue
 else:
  maxR = R[i]
  if maxR - minR > maxB:
   maxB = maxR - minR

print(str(maxB))