Problem:


Score : 400 points

Problem Statement

There are N towns located in a line, conveniently numbered 1 through N. Takahashi the merchant is going on a travel from town 1 to town N, buying and selling apples.

Takahashi will begin the travel at town 1, with no apple in his possession. The actions that can be performed during the travel are as follows:

Move: When at town i (i < N), move to town i + 1.

Merchandise: Buy or sell an arbitrary number of apples at the current town. Here, it is assumed that one apple can always be bought and sold for A_i yen (the currency of Japan) at town i (1 ≦ i ≦ N), where A_i are distinct integers. Also, you can assume that he has an infinite supply of money.

For some reason, there is a constraint on merchandising apple during the travel: the sum of the number of apples bought and the number of apples sold during the whole travel, must be at most T. (Note that a single apple can be counted in both.)

During the travel, Takahashi will perform actions so that the profit of the travel is maximized. Here, the profit of the travel is the amount of money that is gained by selling apples, minus the amount of money that is spent on buying apples. Note that we are not interested in apples in his possession at the end of the travel.

Aoki, a business rival of Takahashi, wants to trouble Takahashi by manipulating the market price of apples. Prior to the beginning of Takahashi's travel, Aoki can change A_i into another arbitrary non-negative integer A_i' for any town i, any number of times. The cost of performing this operation is |A_i - A_i'|. After performing this operation, different towns may have equal values of A_i.

Aoki's objective is to decrease Takahashi's expected profit by at least 1 yen. Find the minimum total cost to achieve it. You may assume that Takahashi's expected profit is initially at least 1 yen.

Constraints

1 ≦ N ≦ 10^5

1 ≦ A_i ≦ 10^9 (1 ≦ i ≦ N)

A_i are distinct.

2 ≦ T ≦ 10^9

In the initial state, Takahashi's expected profit is at least 1 yen.

Input

The input is given from Standard Input in the following format:

N T
A_1 A_2 ... A_N

Output

Print the minimum total cost to decrease Takahashi's expected profit by at least 1 yen.

Sample Input 1

3 2
100 50 200

Sample Output 1

1

In the initial state, Takahashi can achieve the maximum profit of 150 yen as follows:

Move from town 1 to town 2.

Buy one apple for 50 yen at town 2.

Move from town 2 to town 3.

Sell one apple for 200 yen at town 3.

If, for example, Aoki changes the price of an apple at town 2 from 50 yen to 51 yen, Takahashi will not be able to achieve the profit of 150 yen. The cost of performing this operation is 1, thus the answer is 1.

There are other ways to decrease Takahashi's expected profit, such as changing the price of an apple at town 3 from 200 yen to 199 yen.

Sample Input 2

5 8
50 30 40 10 20

Sample Output 2

2

Sample Input 3

10 100
7 10 4 5 9 3 6 8 2 1

Sample Output 3

2



Sample input:
3 2
100 50 200


Sample output:
1

Submission status: Runtime Error

Solution code:
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]

    N,_ = LI()
    N0 = 2 ** N.bit_length()
    st = [0] * (N0*2)

    def add(p,x):
        p += N0-1
        st[p] = x
        while p > 0:
            p = (p-1) // 2
            st[p] = max(st[p*2+1],st[p*2+2])

    def get(a,b,x,l,r):
        if a <= l and r <= b: return st[x]
        if a >= r or b <= l: return 0
        vl = get(a,b,x*2+1,l,(l+r)//2)
        vr = get(a,b,x*2+2,(l+r)//2,r)
        return max(vl,vr)
    
    A = []
    for a in enumerate(sys.stdin.readline().split()):
        a = int(a)
        A.append(a)
        add(e+1,a)
    max_a = -1
    max_cnt = 0
    for i in range(1,N):
        a = get(i+1,N+1,0,0,N0) - A[i-1]
        if a > max_a:
            max_a = a; max_cnt = 1
        elif a == max_a:
            max_cnt += 1

    print(max_cnt)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
town, apple = map(int, input().split())

prices = [int(x) for x in input().split(' ')]

revenues = []
for i in range(1, town):
    revenue = 0
    if (prices[i] > prices[i-1]):
        revenue += prices[i] - prices[i-1]
    else:
        revenues += [revenue]

print(revenues.count(max(revenues)))

Submission status: Runtime Error

Solution code:
town, apple = map(int, input().split())

prices = [int(x) for x in input().split(' ')]

revenues = []
for i in range(1, town):
    revenue = 0
    if (prices[i] > prices[i-1]):
        revenue = prices[i] - prices[i-1]
    else:
        revenues += [revenue]

print(revenues.count(max(revenues)))

Submission status: Runtime Error

Solution code:
class SegmentTree():
    """
    update, get を提供するSegmentTree

    Attributes
    ----------
    __n : int
        葉の数。2 ^ i - 1
    __dot :
        Segment function
    __e: int
        単位元
    __node: list
        Segment Tree
    """
    def __init__(self, A, dot, e):
        """
        Parameters
        ----------
        A : list
            対象の配列
        dot :
            Segment function
        e : int
            単位元
        """
        n = 2 ** (len(A) - 1).bit_length()
        self.__n = n
        self.__dot = dot
        self.__e = e
        self.__node = [e] * (2 * n)
        for i in range(len(A)):
            self.__node[i + n] = A[i]
        for i in range(n - 1, 0, -1):
            self.__node[i] = self.__dot(self.__node[2 * i], self.__node[2 * i + 1])
    
    def update(self, i, c):
        i += self.__n
        node = self.__node
        node[i] = c
        while i > 1:
            i //= 2
            node[i] = self.__dot(node[2 * i], node[2 * i + 1])

    def get(self, l, r):
        vl, vr = self.__e, self.__e
        l += self.__n
        r += self.__n
        while (l < r):
            if l & 1:
                vl = self.__dot(vl, self.__node[l])
                l += 1
            l //= 2
            if r & 1:
                r -= 1
                vr = self.__dot(vr, self.__node[r])
            r //= 2
        return self.__dot(vl, vr)


def main():
    import sys
    readline = sys.stdin.readline
    # readlines = sys.stdin.readlines
    N, T = map(int, input().split())
    A = list(map(int, readline().split()))

    L = SegmentTree(A, min, float('inf'))
    R = SegmentTree(A, max, 0)

    profit = 0
    for i in range(N):
        l = L.get(0, i + 1)
        r = R.get(i, N + 1)
        profit = max(profit, r - l)
    
    cnt = 0
    for i in range(N):
        l = L.get(0, i + 1)
        r = R.get(i, N + 1)
        if r - l == profit:
            if l == A[i]:
                L.update(i, l - 1)
            else:
                R.update(i, r + 1)
            cnt += 1
    
    print(cnt)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
N,T = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
ind = 0
rieki = []
while True:
    ma = max(a[ind+1:N])
    kioku = ind+1
    ind = a.index(ma)
    if kioku != ind:
        mi = min(a[kioku:ind])
        rieki.append(ma-mi)
    if ind == N-1:
        break
print(rieki.count(max(rieki)))

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10000000)

N, T = map(int, input().split())
A = list(map(int, input().split()))

D = [0]

def f(a):
  if a <= N:
    M = max(A[a:N+1])
    Mi = A.index(M)
    m = min(A[a-1:Mi])
    d = M - m
    if D[-1] == d:
      D.append(d)
    elif D[-1] < d:
      D.clear()
      D.append(d)
    f(Mi+2)
  else:
    pass

f(1)

result = len(D)
print(result)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(1000000)

N, T = map(int, input().split())
A = list(map(int, input().split()))

D = [0]

def f(a):
  if a <= N:
    M = max(A[a:N+1])
    Mi = A.index(M)
    m = min(A[a-1:Mi])
    d = M - m
    if D[-1] == d:
      D.append(d)
    elif D[-1] < d:
      D.clear()
      D.append(d)
    f(Mi+2)
  else:
    pass

f(1)

result = len(D)
print(result)

Submission status: Runtime Error

Solution code:
N, T = map(int, input().split())
A = list(map(int, input().split()))

D = [0]

def f(a):
  if a <= N:
    M = max(A[a:N+1])
    Mi = A.index(M)
    m = min(A[a-1:Mi])
    d = M - m
    if D[-1] == d:
      D.append(d)
    elif D[-1] < d:
      D.clear()
      D.append(d)
    f(Mi+2)
  else:
    pass

f(1)

result = len(D)
print(result)

Submission status: Runtime Error

Solution code:
N, T = map(int, input().split())
A = list(map(int, input().split()))

D = []

def f(a):
  if a <= N:
    M = max(A[a:N+1])
    Mi = A.index(M)
    m = min(A[a-1:Mi])
    D.append(M - m)
    f(Mi+2)
  else:
    pass

f(1)

result = D.count(max(D))
print(result)

Submission status: Runtime Error

Solution code:
n, t = map(int, input().split())
a = list(map(int, input().split()))

ans = []
for i in range(n):
    b = max(a[i+1:]) - a[i]
    ans.append(b)

r = max(ans)
print(ans.count(r))

Submission status: Runtime Error

Solution code:
N, T = map(int, input().split())
A = [int(c) for c in input().split()]
p = A[0]
flag = True
ls = []
st = A[-1]
for i in range(N-2,-1-1):
  if st-A[i]>0:
    ls += [st-A[i]]
  else:
    st = A[i]
ls.sort()
ans = ls.count(ls[-1])
print(ans)

Submission status: Runtime Error

Solution code:
N, T = map(int, input().split())
A = [int(c) for c in input().split()]
p = A[0]
flag = True
ls = []
st = A[0]
for i in range(1,N):
  if A[i]>=A[i-1]:
    flag = True
  else:
    if flag:
      ls += [A[i-1]-st]
    flag = False
    st = A[i]
ls.sort()
ans = ls.count(ls[-1])
print(ans)

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N, T = rl()
A = np.array(rl())
A_cummin = A.minimum.accumulate(A)
B = A - A_cummin

answer = (B == B.max()).sum()
print(answer)

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N, T = rl()
A = rl()
B = np.array(A)
answer = 1
profit = 0
for i in range(N):
    B = B[1:] 
    p = B.max() - A[i]
    if p > profit:
        profit = p
        answer = 1
    elif p == profit:
        answer += 1

print(answer)

# 40

Submission status: Runtime Error

Solution code:
n,t=map(int,input().split())
a=list(map(int,input().split()))
b=[[a[i],i] for i in range(n)]
b.sort(reverse=True)
lmin=[a[0]]
rmax=[max(a[1:])]
mxls=[rmax[0]-lmin[0]]
mx=0
mn=n-1
for i in range(1,n):
  if a[i]<=b[mn]:
    mn-=1
  if a[i]>=b[mx]:
    mx+=1
  lmin.append(b[mn])
  rmax.append(b[mx])
  mxls.append(b[mx]-b[mn])
print(mxls.count(max(mxls)))

Submission status: Runtime Error

Solution code:
n,t = map(int,input())
A = list(map(int,input().split()))
m = 10**9+1 
M = -1
ans = 0
for i in range(n):
    x = A[i]
    m = min(x)
    p = x-A
    if p > M:
        ans = 0
        M = p
    elif p == M:
        ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
import copy
 
n, t = map(int, input().split())
L = [int(i) for i in input().split()]
LL = copy.deepcopy(L)
 
minvalue = L[0]
maxvalue = max(LL)
subt = 0
count = 1
flag = 0
j = 0
for i in range(n-1):
  if minvalue > L[i]:
    minvalue = L[i]
    flag = 1

  if maxvalue == L[i]:
    LL = LL[i-j+1:]
    maxvalue = max(LL)
    j = i+1
 
  tsubt = maxvalue - minvalue
  if tsubt > subt:
    subt = tsubt
    count = 1
  elif tsubt == subt and flag == 1:
    count += 1
  flag = 0
  print(LL)
  print("L[i]:{0}, min:{1}, max:{2}, subt:{3}, count:{4}".format(L[i], minvalue, maxvalue, subt, count))

print(count)

Submission status: Runtime Error

Solution code:
from copy import*
from collections import*
from numpy import*
from itertools import*
a,b=map(int,input().split())
*c,=map(int,input().split())
c1=deepcopy(c)
c2=deepcopy(c)

for i in range(1,a):
    c1[i]=min(c1[i-1],c1[i])
for i in range(a-1,0,-1):
    c2[i-1]=max(c2[i],c2[i-1])

#print(c1,c2)
d=array([k for k,v in groupby(c2)])-array([k for k,v in groupby(c1)])
#print(d)
#print(list(d).count(max(d)))

Submission status: Runtime Error

Solution code:
from copy import*
from collections import*
from numpy import*
from itertools import*
a,b=map(int,input().split())
*c,=map(int,input().split())
c1=deepcopy(c)
c2=deepcopy(c)

for i in range(1,a):
    c1[i]=min(c1[i-1],c1[i])
for i in range(a-1,0,-1):
    c2[i-1]=max(c2[i],c2[i-1])

#print(c1,c2)
d=array([k for k,v in groupby(c2)])-array([k for k,v in groupby(c1)])
#print(d)
print(list(d).count(max(d)))

Submission status: Runtime Error

Solution code:
[n,t]=list(map(int,input().split()))
alist=list(map(int,input().split()))

"""
alist.reverse()
n=n-1
dp=[[0 for j in range(n)]for k in range(n)]
for i in range(n-1):
	dp[i][i+1]=alist[i+1]-alist[i]
	
for i in reversed(range(0,n-1)):
	for j in range(n-1-i):
		dp[i][i+2+j]=dp[i][i+1]+dp[i+1][i+2+j]

maximum=max(dp[0])
for i in range(1,n):
	if maximum<max(dp[i]):
		maximum=max(dp[i])
kosu=0
for i in range(0,n):
	kosu=kosu+dp[i].count(maximum)
print(kosu)
"""

salist=[]
for i in range(n-1):
	saisho=min(alist[0:i])
	salist.append(alist[i+1]-saisho)
saidai=max(salist)
kaisu=salist.count(saidai)
print(kaisu)

Submission status: Runtime Error

Solution code:
[n,t]=list(map(int,input().split()))
alist=list(map(int,input().split()))
alist.reverse()
n=n-1
dp=[[0 for j in range(n)]for k in range(n)]
for i in range(n-1):
	dp[i][i+1]=alist[i+1]-alist[i]
	
for i in reversed(range(0,n-1)):
	for j in range(n-1-i):
		dp[i][i+2+j]=dp[i][i+1]+dp[i+1][i+2+j]

maximum=max(dp[0])
for i in range(1,n):
	if maximum<max(dp[i]):
		maximum=max(dp[i])
kosu=0
for i in range(0,n):
	kosu=kosu+dp[i].count(maximum)
print(kosu)

Submission status: Runtime Error

Solution code:
n,t=map(int,input().split())
a=list(map(int,input().split()))
c=[]
d=[0]*(10**5)
if a[0]<a[1]:
    c.append([a[0],0])
else:
    d[0]=a[0]
for i in range(1,n-1):
    if a[i]>a[i+1] and a[i-1]<a[i]:
        d[i]=a[i]
    if a[i]<a[i+1] and a[i-1]>a[i]:
        c.append([a[i],i])
d[n-1]=a[n-1]
e=[0]*(10**5)
for i in c:
    E=max(d[i[1]:])-i[0]
    e[E]+=1
print(max(e))

Submission status: Runtime Error

Solution code:
n,t=map(int,input().split())

a=list(map(int,input().split()))
c=[]
d=[0]*(10**5)
if a[0]<a[1]:
    c.append([a[0],0])
else:
    d[0]=a[0]
for i in range(1,n-1):
    if a[i]>a[i+1] and a[i-1]<a[i]:
        d[i]=a[i]
    if a[i]<a[i+1] and a[i-1]>a[i]:
        c.append([a[i],i])
d[n-1]=a[n-1]
e=[0]*(10**5)
for i in c:
    E=max(d[i[1]:])-i[0]
    e[E]+=1
print(max(e))

Submission status: Runtime Error

Solution code:
N, T = map(int, input().split())
A = list(map(int, input().split()))

n = T // 2

d = -float("inf")
cnt = 1
l = 0
for r in range(1, N - 1):
    if A[l] < A[r]:
        if A[r] > A[r + 1]:
            if d == A[r] - A[l]:
                cnt += 1
            elif d < A[r] - A[l]:
                d = A[r] - A[l]
                cnt = 1
    else:
        l = r
        r += 1
else:
    if d == A[r] - A[l]:
        cnt += 1
    elif d < A[r] - A[l]:
        d = A[r] - A[l]
        cnt = 1
    print(cnt)

Submission status: Runtime Error

Solution code:
N, T = map(int, input().split())
A = list(map(int, input().split()))

max_bef = 0
cnt = 0
A_min = A[0]

for i in range(1,N):
    tmp = A[i] - A_min
    if max_bef < tmp:
        max_bef = tmp
        cnt = 1
    if max_bef == tmp:
        cnt += 1
    a_min = min(a_min, a[i])

print(cnt)

Submission status: Runtime Error

Solution code:
# minより右側にあるmaxの差 * Tすれば最大になる。その差が同じペアは別解としてある
# でもこうするとTの値は意味ないよなぁ
# 「自分より左側で最小の数」「自分より右側で最大の数」の配列を作って、再度頭からなめていけば最大の差とそれをとるペアがわかる
n, t = map(int, input().split())
arr = list(map(int, input().split()))
min_arr = []
max_arr = []
now_min, now_max = 10**9, -1
for i in range(n):
    if now_min > arr[i]:
        now_min = arr[i]
        min_arr.append(now_min)
    if now_max < arr[-i - 1]:
        now_max = arr[-i-1]
        max_arr.append(now_max)

max_arr = list(reversed(max_arr))
print(min_arr)
print(max_arr)
max_dif = 0
dif_paris = []
for i in range(len(max_arr)):
    if max_arr[i] - min_arr[i] > max_dif:
        max_dif = max_arr[i] - min_arr[i]
        dif_paris.clear()
        dif_paris.append([max_arr[i], min_arr[i]])
    elif max_arr[i] - min_arr[i] == max_dif:
        dif_paris.append([max_arr[i], min_arr[i]])

print(len(dif_paris))

Submission status: Runtime Error

Solution code:
# minより右側にあるmaxの差 * Tすれば最大になる。その差が同じペアは別解としてある
# でもこうするとTの値は意味ないよなぁ
# 「自分より左側で最小の数」「自分より右側で最大の数」の配列を作って、再度頭からなめていけば最大の差とそれをとるペアがわかる
n, t = map(int, input().split())
arr = list(map(int, input().split()))
min_arr = []
max_arr = []
now_min, now_max = 10**9, -1
for i in range(n):
    if now_min > arr[i]:
        now_min = arr[i]
        min_arr.append(now_min)
    if now_max < arr[-i - 1]:
        now_max = arr[-i-1]
        max_arr.append(now_max)

max_arr = list(reversed(max_arr))
max_dif = 0
dif_paris = []
for i in range(len(max_arr)):
    if max_arr[i] - min_arr[i] > max_dif:
        max_dif = max_arr[i] - min_arr[i]
        dif_paris.clear()
        dif_paris.append([max_arr[i], min_arr[i]])
    elif max_arr[i] - min_arr[i] == max_dif:
        if [max_arr[i], min_arr[i]] not in dif_paris:
            dif_paris.append([max_arr[i], min_arr[i]])

print(len(dif_paris))

Submission status: Runtime Error

Solution code:
# minより右側にあるmaxの差 * Tすれば最大になる。その差が同じペアは別解としてある
# でもこうするとTの値は意味ないよなぁ
# 「自分より左側で最小の数」「自分より右側で最大の数」の配列を作って、再度頭からなめていけば最大の差とそれをとるペアがわかる
n, t = map(int, input().split())
arr = list(map(int, input().split()))
min_arr = [10e9 for _ in range(n)]
max_arr = [-1 for _ in range(n)]
now_min, now_max = 10e9, -1
for i in range(n):
    if now_min > arr[i]:
        now_min = arr[i]
    min_arr[i] = now_min
    if now_max < arr[-i - 1]:
        now_max = arr[-i-1]
    max_arr[-i - 1] = now_max


max_dif = 0
dif_paris = []
for i in range(n):
    if max_arr[i] - min_arr[i] > max_dif:
        max_dif = max_arr[i] - min_arr[i]
        dif_paris.clear()
        dif_paris.append([max_arr[i], min_arr[i]])
    elif max_arr[i] - min_arr[i] == max_dif:
        if [max_arr[i], min_arr[i]] not in dif_paris:
            dif_paris.append([max_arr[i], min_arr[i]])

print(len(dif_paris))

Submission status: Runtime Error

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

N,T = map(int,input().split())
A = [int(i) for i in input().split()]

L_min = [mod for i in range(N)]
L_min[0] = A[0]
for i in range(1,N):
    L_min[i] = min(L_min[i-1],A[i])

A.reverse()
R_max = [0 for i in range(N)]
R_max[0] = A[0]
for i in range(1,N):
    R_max[i] = max(R_max[i-1],A[i])

R_max.reverse()

ans = 0
dif = 0
# print(R_max)
# print(L_min)
for i in range(1,N):
    if dif < R_max[i] - L_min[i]:
        dif = R_max[i] - L_min[i]
        r,l = R_max[i],L_min[i]
        # print(dif)
        ans = 1
    elif dif == R_max[i] - L_min[i]:
        if r == R_max[i]:
            pass
        else:
            r,l = R_max[i],L_min[i]
            ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
N, T = map(int, input().split())

dp_matrix = np.zeros((N, N + 1))

price_list = np.array(list(map(int, input().split())))
price_list = price_list.reshape((N, 1))

def max_selecting(m1, m2):
    '''
    input:
    m1, m2: np matrix (same size)
    output:
    m: np matrix
    '''
    m_bool1 = m1 > m2
    m_bool2 = m1 <= m2
    m = m1 * m_bool1 + m2 * m_bool2
    return m
  
diff = np.triu(price_list.T - price_list).T
for i in range(1, N+1):
    dp_matrix[:, i] = max_selecting(dp_matrix[:, i-1], diff[i-1]) 
    
print(np.sum(dp_matrix[:, N] == np.max(dp_matrix[:, N])))

Submission status: Runtime Error

Solution code:
n,t = map(int,input().split())
a = list(map(int,input().split()))
ma = inf
benefit = 0
ans = 1
for i in range(n):
    if a[i] < ma:
        ma = a[i]
    else:
        b = a[i]-ma
        if b == benefit:
            ans += 1

        if b > benefit:
            benefit = b
            ans = 1
print(ans)

Submission status: Runtime Error

Solution code:
n,t = map(int,input().split())
a = list(map(int,input().split()))
i = 0
j = 0
p = 0
c = 0
while 1:
    while i < n-1:
        if a[i] > a[i+1]:
            i += 1
        else:
            break
    if i >= n-1:
        break
    j = i+1
    while a[j] < [j+1]:
        j += 1
    if j >= n-1:
        break
    p1 = a[j]-a[i]
    if p < p1:
        c = 1
        p = p1
    elif p == p1:
        c += 1
        p = p1
    i = j+1
    if i >= n-1:
        break
print(c)

Submission status: Runtime Error

Solution code:
n,t = map(int,input().split())
a = list(map(int,input().split()))
i = 0
j = 0
p = 0
c = 0
while 1:
    while i < n-1:
        if a[i] > a[i+1]:
            i += 1
        else:
            break
    if i >= n-1:
        break
    j = i+1
    while a[j] < [j+1]:
        j += 1
    if j>= n-1:
        break
    p1 = a[j]-a[i]
    if p < p1:
        c = 1
        p = p1
    elif p == p1:
        c += 1
        p = p1
    i = j+1
print(c)

Submission status: Runtime Error

Solution code:
n,t = map(int,input().split())
a = list(map(int,input().split()))
i = 0
j = 0
p = 0
c = 0
while 1:
    while i < n-1:
        if a[i] > a[i+1]:
            i += 1
        else:
            break
    if i >= n-1:
        break
    j = i+1
    while a[j] < [j+1]:
        j += 1
    p1 = a[j]-a[i]
    if p < p1:
        c = 1
        p = p1
    elif p == p1:
        c += 1
        p = p1
    i = j+1
print(c)

Submission status: Runtime Error

Solution code:
n,t = map(int,input().split())
a = list(map(int,input().split()))
i = 0
p = 0
c = 0
while i < n:
    while i < n:
        if a[i] > a[i+1]:
            i += 1
        else:
            break
    p1 = max(a[i+1:])-a[i]
    if p <= p1:
        c += 1
        p = p1
    i = a.index(max(a[i+1:])) + 1
print(c)

Submission status: Runtime Error

Solution code:
n,t = map(int,input().split())
a = list(map(int,input().split()))
i = 0
p = 0
c = 0
while 1:
    while i < n:
        if a[i] > a[i+1]:
            i += 1
        else:
            break
    if i >= n-1:
        break
    p1 = max(a[i:])-a[i]
    if p <=p1:
        c += 1
        p = p1
    i = a.index(max(a[i:])) + 1
print(c)

Submission status: Runtime Error

Solution code:
n, t = list(map(int, input().split()))
a = list(map(int, input().split()))

remain_max = [a[-1]]*n
for i in range(1, n):
    remain_max[-(i+1)] = max(a[-i], remain_max[-i])

diffs = [0]*n
for i in range(n):
    diffs[i] = remain_max[i] - a[i]

max_diff = 0
ans = 0
for i in range(n):
    if diffs[i] > max_diff:
        max_diff = diffs[i]
        ans = 1
    elif diffs[i] == max_diff:
        ans1 += 1

print(ans)

Submission status: Runtime Error

Solution code:
# coding: utf-8
 
# R: Right hand side
# L: Left  hand side
def add_stone(stone, pos, searched_stones):
    sample = searched_stones[::[1, -1][pos == "R"]]
    if sample[0] == stone:
        return None
 
    for n, s in enumerate(sample[1:]):
        if s == stone:
            return (stone * (n + 2) + sample[1 + n:])[::[1, -1][pos == "R"]]
 
 
def stones_bfs(searched_stones):
    
    queue = [searched_stones + "0"]
    patterns = [["B", "R"], ["B", "L"], ["W", "R"], ["W", "L"]]
    
    while queue:
        stones = queue.pop(0)
        if (stones.count("W") == len(stones) - 1 |
            stones.count("B") == len(stones) - 1):
            return int(stones[-1])
            
        for p in patterns:
            s = add_stone(*p, stones[:-1])
            if s is not None:
                queue += [s + str(int(stones[-1]) + 1)]
 
print(stones_bfs(input().strip()))

Submission status: Runtime Error

Solution code:
n, t = list(map(int, input().split()))
a = list(map(int, input().split()))
min = 1000000000
min_c = 0
max_dif = 0
max_dif_c = 0
for i in range(n):
    if a[i] < min:
        min = a[i]
        min_c = 1
        continue
    elif a[i] == min:
        min_c += 1
        continue
    if a[i] - min > max_dif:
        max_dif = a[i] - min
        max_dif_c = 1
    elif a[i] - min == max_dif:
        max_dif_c += 1
c = min([min_c, max_dif_c])
print(str(c))

Submission status: Runtime Error

Solution code:
n, t = list(map(int, input().split()))
a = list(map(int, input().split()))
min = 1000000000
min_c = 0
max_dif = 0
max_dif_c = 0
for i in range(n):
    if a[i] < min:
        min = a[i]
        min_c = 1
    elif a[i] == min:
        min_c += 1
    if a[i] - min > max_dif:
        max_dif = a[i] - min
        max_dif_c = 1
    elif: a[i] - min == max_dif:
        max_dif_c += 1
c = min([min_c, max_dif_c])
print(str(c))

Submission status: Runtime Error

Solution code:
n, t = list(map(int, input().split()))
a = list(map(int, input().split()))
c = 0
max_dif = 0
for i in range(n):
    for j in range(i + 1, n):
        if a[j] - a[i] > max_dif:
            c = 1
            max_dif = a[j] - a[i]
        elif: a[j] - a[i] == max_dif:
            c += 1
print(str(c))

Submission status: Runtime Error

Solution code:
n, t = list(map(int, input().split()))
a = list(map(int, input().split()))
c = 0
max_dif = 0
for i in range(n):
    for j in range(i + 1, n):
        if a[j] - a[i] > max_dif:
            c = 1
            max_dif = a[j] - a[i]
        elif: a[j] - a[i] == max_dif:
            c += 1
print(c)

Submission status: Runtime Error

Solution code:
n, t = list(map(int, input().split()))
a = list(map(int, input().split()))
c = 0
max_dif = 0
for i in range(n):
    for j in range(i, n):
        if a[j] - a[i] > max_dif:
            c = 1
            max_dif = a[j] - a[i]
        elif: a[j] - a[i] == max_dif:
            c += 1
print(c)

Submission status: Runtime Error

Solution code:
IS=float('inf')
x=IS
y=0
for i in a:
    if x>i:
        x=i
    elif y<i:
        y=i
    if i-x>chk:
        ans=1
    elif i-x==chk:
        ans+=1
    chk=max(chk,i-x)
print ans

Submission status: Runtime Error

Solution code:
list1 = input().split()
n = int(list1[0])
t = int(list1[1])
a = input().split()

list = []
l = 0
i = 0
while l < n:
   i = l + 1
      if i == n:
       list.append(int(a[i-1])-int(a[l]))     
       break
      else: 
       while i < n:
        if a[i-1]<a[i]:
           i += 1
        else:
           list.append(int(a[i-1])-int(a[l]))
           break
   l += 1

print(list.count(max(list)))

Submission status: Runtime Error

Solution code:
INF = 1000000
n, m = list(map(int, input().split()))
a = list(map(int, input().split())) + [0]
b = a[0]
arr = []

for i in range(1, n+1):
    if a[i - 1] > a[i]:
        x = a[i - 1] - b
        arr += [x] if x != 0 else []
        b = a[i]

mx = max(arr)g
ans = min(arr.count(mx),m//2)
print(ans)