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: Accepted

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

b=A[0]
B=[b]*(n-1)
for i in range(1,n):
  b=min(b,A[i])
  B[i-1]=A[i]-b
print(B.count(max(B)))

Submission status: Accepted

Solution code:
n,t=map(int,input().split())
l=list(map(int,input().split()))
m=l[-1]
ma=[m]*n
for i in range(n):
    m=max(m,l[n-1-i])
    ma[n-1-i]=m
for i in range(n):
    l[i]=ma[i]-l[i]
k=max(l)
ans=0
for i in l:
    if i==k:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
N,T=list(map(int,input().split(" ")))
A=list(map(int,input().split(" ")))
sub=defaultdict(lambda:0)
max1=A[0]
min1=A[0]
for i in range(N):
    if A[i]>=max1>=min1:
        max1=A[i]
        sub[max1-min1]+=1
    elif max1>=A[i]>=min1:
        max1=A[i]
        sub[max1-min1]+=1
    elif min1>=A[i]:
        min1=A[i]
        max1=A[i]
a=list(sub.keys())
b=max(a)
print(sub[b])

Submission status: Accepted

Solution code:
# 2019/10/09
# 解説かんにんぐ

n,t=map(int,input().split())
a=list(map(int,input().split()))
min_a=float('inf')
cost={}
for i in range(n):
    min_a=min(min_a,a[i])
    c=a[i]-min_a
    cost[c]=cost.get(c,0)+1
print(cost[max(cost.keys())])

Submission status: Accepted

Solution code:
n,t = map(int,input().split())
a =list(map(int,input().split()))
MIN = float("inf")
b = [0] * n
for i in range(n):
  MIN = min(MIN,a[i])
  b[i] = a[i]-MIN
print(b.count(max(b)))

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
k=list(map(int,input().split()))

sa=0
ans=1

n=k[a-1]

for i in range(a-2,-1,-1):
    if k[i]>n:
        n=k[i]
    tmp=n-k[i]
    if tmp>sa:
        sa=tmp
        ans=1
    elif tmp==sa:
        ans+=1

    

print(ans)

Submission status: Accepted

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

a = a[::-1]
m = [0] * n


for i in range(n):
    if i == 0:
        m[i] = a[i]
    else:
        m[i] = max(a[i], m[i-1])

a = a[::-1]
m = m[::-1]

#print(m)

sa = [0] * n
for i in range(n):
    sa[i] = m[i] - a[i]

#print(sa)

ans_max = max(sa)
ans = sa.count(ans_max)
print(ans)

Submission status: Accepted

Solution code:
n, t = map(int, input().split())
ls = list(map(int, input().split()))
ms = []
m = ls[-1]
for x in ls[1:][::-1]:
    m = max(m, x)
    ms.append(m)
ms = ms[::-1]
ds = [m - x for x, m in zip(ls[:-1], ms)]
m = max(ds)
print(sum([1 for d in ds if d == m]))

Submission status: Accepted

Solution code:
n, t = map(int, input().split())
a = [int(i) for i in input().split()]
min_a = a[0]
max_a = a[0]
diff = 0
num = 0
for aa in a:
    if min_a > aa:
        min_a = aa
        max_a = aa
    elif min_a < aa:
        if aa - min_a > diff:
            diff = aa - min_a
            num = 1
        elif aa - min_a == diff:
            num += 1
print(num)

Submission status: Accepted

Solution code:
import numpy as np
N,T = map(int,input().split())
A = np.array(list(map(int,input().split())))
A_cummin = np.minimum.accumulate(A)
profit = A - A_cummin
ans = (profit == profit.max()).sum()
print(ans)

Submission status: Accepted

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

A_cummin = np.minimum.accumulate(A)

profit = A - A_cummin

ans = (profit == profit.max()).sum()

print(ans)

Submission status: Accepted

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

maxa = a[n-1]
sa = 0
res = 1
for i in range(n-1,-1,-1):
    if a[i] > maxa:
        maxa = a[i]
    tsa = maxa - a[i]
    if tsa > sa:
        sa = tsa
        res =1
    elif tsa == sa:
        res += 1

print(res)

Submission status: Accepted

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


#最小値が更新された時にそれまでの利益の最大値を候補としてリストに追加
a.append(0)
mini = 10e10
maxval = 0
maxvals = []
for x in a:
    if mini > x:
        mini = x
        maxvals.append(maxval)
        maxval = 0
    else:
        maxval = max(maxval, x - mini)

print(maxvals.count(max(maxvals)))
#3 2
#100 50 200

Submission status: Accepted

Solution code:
n, t = map(int, input().split(" "))
list_a = list(map(int, input().split(" ")))
list_profit = []
min_price = list_a[0]
for a in list_a:
  if min_price < a:
    list_profit.append(a - min_price)
  else:
    list_profit.append(0)
    min_price = a
max_profit = max(list_profit)
print(list_profit.count(max_profit))

Submission status: Accepted

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

M = [0 for _ in range(N-1)] + [A[N-1]]
for i in range(N-2,-1,-1):
  M[i] = max(A[i],M[i+1])

ans = 0
maxp = -(10**9)
for i in range(N):
  #print(M[i],A[i],maxp)
  if M[i]-A[i] > maxp:
    maxp = M[i]-A[i]
    ans = 1
  elif M[i]-A[i] == maxp:
    ans += 1
print(ans)

Submission status: Accepted

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

mi = A[0]
ma = 0
cnt = 0
for i in range(1, N):
  if mi > A[i]:
    mi = A[i]
  else:
    if A[i] - mi == ma:
      cnt += 1
    elif A[i] - mi > ma:
      cnt = 1
      ma = A[i] - mi
print(cnt)

Submission status: Accepted

Solution code:
N,T=map(int,input().split())
A=[int(x) for x in input().split()]

maxA=[0]*(N+1)
minA=[10**10]*(N+1)

for i in range(N):
  maxA[N-i-1]=max(maxA[N-i],A[N-i-1])
  minA[i+1]=min(minA[i],A[i])

b = 0
for i in range(N+1):
  b=max(b,maxA[i]-minA[i])
tmp = -1
cnt = 0
for i in range(N):
  if maxA[i]-minA[i]==b:
    tmp=maxA[i]
  if A[i]==tmp:
    cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
def main():
    n,t = map(int,input().split())
    a = [int(x) for x in input().split()]
    mx,mn = 0,10**9
    profit = [0 for _ in range(n)]
    for i in range(n-1,-1,-1):
        now = a[i]
        mx = max(mx,now)
        profit[i] = mx-now
    mx = max(profit)
    print(profit.count(mx))
if __name__ == "__main__":
    main()

Submission status: Accepted

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

profit = 0
prof_n = 0

mn = 0
for i in range(n):
    if i == 0:
        mn = a[i]
        continue
    if a[i] < mn:
        mn = a[i]
    else:
        if a[i] - mn > profit:
            profit = a[i] - mn
            prof_n = 1
        elif a[i] - mn == profit:
            prof_n += 1

ans = prof_n
print(ans)

Submission status: Accepted

Solution code:
import itertools

N,T = list(map(int,input().split(" ")))
As = list(map(int,input().split(" ")))
ans = 1
ma = -1
l = 0
for r,a in enumerate(As):
    if a < As[l]:
        l = r

    if a - As[l] >0:
        if a - As[l] > ma:
            ma = a - As[l]
            ans = 1
        elif a - As[l] == ma:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
from itertools import accumulate
_,_,*a,=map(int,open(0).read().split())
m=c=0
for x,y in zip(a,accumulate(a,min)):
	if x-y==m:c+=1
	elif x-y>m:m=x-y;c=1
print(c)

Submission status: Accepted

Solution code:
from itertools import accumulate
def solve():
	_,_,*a=map(int,open(0).read().split())
	c=[x-y for x,y in zip(a,accumulate(a,min))]
	print(c.count(max(c)))
if __name__=="__main__":
	solve()

Submission status: Accepted

Solution code:
def solve():
	_,_,*a=map(int,open(0).read().split());c=[x-y for x,y in zip(a,__import__("itertools").accumulate(a,min))];print(c.count(max(c)))
if __name__=="__main__":solve()

Submission status: Accepted

Solution code:
_,_,*a=map(int,open(0).read().split());c=[x-y for x,y in zip(a,__import__("itertools").accumulate(a,min))];print(c.count(max(c)))

Submission status: Accepted

Solution code:
from itertools import*;_,a=open(0);*a,=map(int,a.split());c=[x-y for x,y in zip(a,accumulate(a,min))];print(c.count(max(c)))

Submission status: Accepted

Solution code:
N,T=list(map(int,input().split()))
A=list(map(int,input().split()))
maxval=[0 for i in range(N)]
maxdif=[0 for i in range(N)]
for i in range(N):
    if i==0:
        maxval[N-1-i]=A[N-1]
        maxdif[N-1-i]=0
    else:
        maxval[N-1-i]=max(maxval[N-i],A[N-i-1])
        maxdif[N-1-i]=maxval[N-1-i]-A[N-1-i]

print(maxdif.count(max(maxdif)))

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
nums = list(map(int, input().split()))
INF = 10**10
min_num = INF
max_diff = 0
cnt = 0
for num in nums:
  if num-min_num > max_diff:
    cnt = 1
    max_diff = num-min_num
  elif num-min_num == max_diff:
    cnt += 1
  if num < min_num:
    min_num = num
print(cnt)

Submission status: Accepted

Solution code:
import numpy as np

N, T = map(int, input().split())
A = np.array(input().split(), dtype=np.int32)

# 自分より左にある最安値
A_cummin = np.minimum.accumulate(A)
# 差額
profit = A - A_cummin

ans = (profit == profit.max()).sum()
print(ans)

Submission status: Accepted

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

amin = A[0]
sa_max = [0, 0]
for i in range(1, n):
    if sa_max[0] < A[i]-amin:
        sa_max[0] = A[i]-amin
        sa_max[1] = 1
    elif sa_max[0] == A[i]-amin:
        sa_max[1] += 1
    amin = min(amin, A[i])
    # print(sa_max)

print(sa_max[1])

Submission status: Accepted

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

l = A[0]
mp = 0
for i in range(1, N):
    if A[i]-l > mp:
        mp = A[i]-l
        c = 1
    elif A[i]-l == mp:
        c += 1
    elif A[i] < l:
        l = A[i]

print(c)

Submission status: Accepted

Solution code:
n,t=map(int,input().split())
a=list(map(int,input().split()))
b=[]
m=a[0]
for i in range(1,n):
  b.append(a[i]-m)
  m=min(m,a[i])
x=max(b)
ct=0
for i in range(len(b)):
  if b[i]==x:
    ct+=1
print(ct)

Submission status: Accepted

Solution code:
import sys
from collections import Counter
N, T = map(int, input().split())
A = [int(_) for _ in input().split()]

if N == 2:
    print(1)
    sys.exit()

start = A[0]
max_diff = 0
max_count = 0


for n in range(1, N):
    if A[n] < A[n - 1]:
        start = min(A[n], start)
        #print(start)
    else:
        diff = A[n] - start
        if diff > max_diff:
            max_diff = diff
            max_count = 1
        elif diff == max_diff:
            max_count += 1


print(max_count)

Submission status: Accepted

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

B = [0] * (N-1)
minA = A[0]
for i in range(1, N):
    if A[i] < minA:
        minA = A[i]
    B[i-1] = A[i] - minA
B.sort(reverse=True)
ans = 0
for i in B:
    if i == B[0]:
        ans += 1
    else:
        break
print(ans)

Submission status: Accepted

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

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

a_min = [a[0]] * n
a_diff_max = 0
for i in range(1, n):
    a_min[i] = min(a[i], a_min[i-1])
    a_diff_max = max(a_diff_max, a_max[i] - a_min[i-1])

a_min_max = set()
for i in range(n-1):
    if a_max[i+1] - a_min[i] == a_diff_max:
        a_min_max.add((a_max[i+1], a_min[i]))

ans = len(a_min_max)
print(ans)

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
A = [int(x) for x in input().split()]

M = [0]*N
D = [0]*N
M[0] = A[0]
D[0] = 0

for i in range(1, N):
    M[i] = min(M[i-1], A[i])
    D[i] = A[i] - M[i]

D = sorted(D,reverse=True)
m = D[0]
cnt = 0
for i in range(N):
    if D[i] == m:
        cnt += 1
    else:
        break
print(cnt)

Submission status: Accepted

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

cost = 0
min_ = A[0]
dist = 0
#print(min_)
#print('dist = ', dist)
#print('cost = ', cost)
for i in range(1, N):
    if min_ > A[i]:
        min_ = A[i]
    dist_tmp = A[i] - min_
    if dist == dist_tmp:
        cost += 1
    elif dist < dist_tmp:
        cost = 1
        dist = dist_tmp
    #print(min_)
    #print('dist = ', dist)
    #print('cost = ', cost)
print(cost)

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
As = list(map(int, input().split()))
if N == 1:
  print(1)
  exit()
Ms = []
m = 0
for i in range(N):
  m = max(m, As[-i-1])
  Ms.append(m)
Ms = list(reversed(Ms))
Ds = []
for i in range(N-1):
  d = Ms[i+1]-As[i]
  Ds.append(d)
dmax = max(Ds)
r = Ds.count(dmax)
print(r)

Submission status: Accepted

Solution code:
from itertools import accumulate
from collections import Counter

N, T, *A = map(int, open(0).read().split())

M = accumulate(A, min)
B = Counter(a - mi for a, mi in zip(A, M))

print(B[max(B.keys())])

Submission status: Accepted

Solution code:
from itertools import accumulate

N, T, *A = map(int, open(0).read().split())

M = accumulate(A, min)
B = {}
for a, mi in zip(A, M):
    b = a - mi
    B[b] = B.get(b, 0) + 1

print(B[max(B.keys())])

Submission status: Accepted

Solution code:
N, T, A0, *A = map(int, open(0).read().split())

mi = A0
B = {}
for a in A:
    b = a - mi
    B[b] = B.get(b, 0) + 1
    mi = min(mi, a)

print(B[max(B.keys())])

Submission status: Accepted

Solution code:
N, T, A0, *A = map(int, open(0).read().split())

ma, mi = 0, A0
B = {}
for a in A:
    b = a - mi
    B[b] = B.get(b, 0) + 1
    ma, mi = max(ma, b), min(mi, a)

print(B[ma])

Submission status: Accepted

Solution code:
from collections import Counter

N, T, *A = map(int, open(0).read().split())

mi = A[0]
ma = 0

B = Counter()
for a in A[1:]:
    b = a - mi
    B[b] += 1
    ma = max(ma, b)
    mi = min(mi, a)

print(B[ma])

Submission status: Accepted

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

B = []
n = A[0]
for a in A:
    B.append(a-n)
    n = min(n, a)

B.sort(reverse=True)
c = 0
for b in B:
    if b == B[0]:
        c += 1
    else:
        break
print(c)

Submission status: Accepted

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

profit_list = []

min_a = 10**9+1
for a in a_list:
    profit_list.append(a-min_a)
    if a<min_a:
        min_a = a

profit_list.sort()

max_profit = profit_list[-1]

cnt = 0
for p in profit_list:
    if p == max_profit:
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
# ABC047D - 高橋君と見えざる手 / An Invisible Hand (ARC063D)
def main():
    N, T, *A = map(int, open(0).read().split())
    cur, cand = A[0], []
    for i in A:
        if i < cur:
            cur = i
        else:
            cand += [i - cur]
    x = max(cand)
    ans = len([1 for i in cand if i == x])
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# ABC047D - 高橋君と見えざる手 / An Invisible Hand (ARC063D)
def main():
    N, T = tuple(map(int, input().split()))
    A = tuple(map(int, input().split()))
    cur, cand = A[0], []
    for i in A:
        if i < cur:
            cur = i
        else:
            cand += [i - cur]
    x = max(cand)
    ans = sum(i == x for i in cand)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n,t=map(int,input().split())
a=list(map(int,input().split()))
kau=1
uru=0
cost=0
min_a=a[0]
min_count=0
max_sa=0
for i in range(1,n):
  if a[i]<min_a:
    min_a=a[i]
    if uru!=0:
      cost+=min(kau,uru)
    kau=1
    uru=0
  elif a[i]==min_a:
    kau+=1
  elif a[i]-min_a>max_sa:
    max_sa=a[i]-min_a
    cost=0
    uru=1
  elif a[i]-min_a==max_sa:
    uru+=1
if uru!=0:
  cost+=min(kau,uru)
print(cost)

Submission status: Accepted

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

A_mi = np.minimum.accumulate(A)
pro = A - A_mi

answer = sum(pro == max(pro))
print(answer)

Submission status: Accepted

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

amin=10**9+1
amax=10**9+1
damax=-1
dacount=0

for a in A:
  if a<amin:
    if damax<amax-amin:
      damax=amax-amin
      dacount=1
  
    elif damax==amax-amin:
      dacount+=1
    amin=a
    amax=amin

  if amax<a:
    amax=a
if damax<amax-amin:
  damax=amax-amin
  dacount=1
elif damax==amax-amin:
  dacount+=1
print(dacount)

Submission status: Accepted

Solution code:
n,t = map(int,input().split())
a = list(map(int,input().split()))
ans = 0
Min = a[0]
dif  = 0
for i in range(1,n):
    if dif < a[i] - Min:
        dif = a[i] - Min
        ans = 1
    elif dif == a[i] - Min:
        ans += 1
    Min = min(Min,a[i])

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
 
#n = int(input())
n,t = [int(i) for i in readline().split()]
a = [int(i) for i in readline().split()]

m = gain = 0
ans = 0
for ai in reversed(a):
    m = max(ai,m)
    if gain < m-ai:
        ans = 1
    elif gain == m-ai:
        ans += 1
    gain = max(gain,m-ai)

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
 
#n = int(input())
n,t = [int(i) for i in readline().split()]
a = [10**9+1]+[int(i) for i in readline().split()]


"""
gain = 0
m = 0
maxid = []
minid = []
memo = {}
for i in range(n-1,-1,-1):
    ai = a[i]
    if ai > m:
        m = ai
        maxid = [i]
        memo.append([minid[:],maxid[:]])
    elif ai == m:
        maxid.append[i]

    m = max(ai,m)
    if gain < m-ai:
        gain = m-ai
        minid = [i]
        memo = []
    elif gain == m-ai:
        minid.append(i)
    
    print(minid,maxid,memo)
"""    

gain = 0
m = 0
for ai in reversed(a):
    m = max(ai,m)
    if gain < m-ai: gain = m-ai

m = 0
mi = ma = 0

ans = 0
for ai in reversed(a):
    if m < ai:
        ans += max(mi,ma)
        mi = ma = 0
    elif m == ai:
        ma += 1

    m = max(m,ai)
    
    if m-ai == gain:
        mi += 1


print(ans)

Submission status: Accepted

Solution code:
N,T = map(int,input().split())
A = list(map(int,input().split()))
B = [-1]
buy = A[0]
for i in A:
    buy = min(i,buy)
    B.append(i-buy)
B.sort(reverse=True)
i = 0
while B[0] == B[i]:
    i += 1
print(i)

Submission status: Accepted

Solution code:
N,T = map(int,input().split())
A = list(map(int,input().split()))
B = []
buy = A[0]
for i in A:
    buy = min(i,buy)
    B.append(i-buy)
B.sort(reverse=True)
i = 0
while B[0] == B[i]:
    i += 1
print(i)

Submission status: Accepted

Solution code:
import collections
n, t = map(int, input().split())
a = list(map(int, input().split()))
mi = 10 ** 9
als = collections.defaultdict(list)
for i, v in enumerate(a):
    mi = min(mi, v)
    pft = v - mi
    als[pft] += [mi]
als = sorted(als.items(), reverse=True)
als = collections.Counter(als[0][1]).most_common()
print(len(als))

Submission status: Accepted

Solution code:
N,T = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
mintmp = float("inf")
difflist = []
for A_i in A:
    mintmp = min(A_i,mintmp)
    difflist.append(A_i-mintmp)
print(difflist.count(max(difflist)))

Submission status: Accepted

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

maxdiff = 0
ct = 0
mintmp = float("inf")
for A_i in A:
    mintmp = min(A_i,mintmp)
    diff = A_i - mintmp
    if diff > maxdiff:
        maxdiff = diff
        ct = 1
    elif diff == maxdiff:
        ct += 1
print(ct)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
l=list(map(int,input().split()))
mintmp=float("inf")
ldef=[]
for i in l:
    mintmp=min(mintmp,i)
    ldef.append(i-mintmp)
print(ldef.count(max(ldef)))

Submission status: Accepted

Solution code:
n, t = map(int, input().split())
a = list(map(int, input().split()))
thenumberofgoodpairs = 0
maxpricedifference = 0
minimumprice = float("inf")
for appleprice in a :
    if minimumprice > appleprice :
        minimumprice = appleprice
    elif appleprice - minimumprice == maxpricedifference :
        thenumberofgoodpairs += 1
    elif appleprice - minimumprice > maxpricedifference :
        maxpricedifference = appleprice - minimumprice
        thenumberofgoodpairs = 1
print(thenumberofgoodpairs)

Submission status: Accepted

Solution code:
n,t=map(int,input().split())
a=list(map(int,input().split()))
b=[a[-1]]
for i in a[::-1][1:]:b.append(max(i,b[-1]))
c=[b[n-i-1]-a[i]for i in range(n)]
print(c.count(sorted(c)[-1]))

Submission status: Accepted

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

ans = 0
temp_min = A[0]
max_diff = 0
for i in range(1, N):
    if A[i] < temp_min:
        temp_min = A[i]
    else:
        diff = A[i] - temp_min
        if diff > max_diff:
            ans = 1
            max_diff = diff
        elif diff == max_diff:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#ABC47 D

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

n,t = map(int,input().split())
a = list(map(int,input().split()))
ma,mi,ans = 0,float('inf'),0
for i in range(n):
    if ma < a[i] - mi:
        ma = a[i] - mi
        ans = 1
    elif ma == a[i] - mi:
        ans += 1
    if mi > a[i]:
        mi = a[i]
    #print(i,ma,mi,ans)
print(ans)

Submission status: Accepted

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

MAX=[0]
MIN=[10**10]

for i in range(n):
    MAX.append(max(a_r[i],MAX[-1]))
    MIN.append(min(a[i],MIN[-1]))
    
MAX.reverse()

MAX=MAX[:n]
MIN=MIN[1:]

t=[MAX[i]-MIN[i] for i in range(n)]

m=max(t)

cnta,cntb=0,0

for i in range(n):
    if t[i]==m:
        if MAX[i]==a[i]:
            cnta+=1
        if MIN[i]==a[i]:
            cntb+=1
print(min(cnta,cntb))

Submission status: Accepted

Solution code:
import functools

def calc_reward(seq):    
    def f(m_r, e):
        return min(m_r[0], e), max(m_r[1], e - m_r[0])
    return functools.reduce(f, seq, (seq[0], 0))[1]

def calc_cost(seq: list):
    mi, ma = min(seq), max(seq)
    if mi == ma:
        return 0
    rev_seq = seq[::-1] 
    return min(seq[seq.index(mi):].count(ma), rev_seq[rev_seq.index(ma):].count(mi))
        
def divide_iter(seq):
    s = [seq[0]]
    for e in seq[1:]:
        if e < s[0]:
            yield s
            s = []
        s.append(e)
    yield s

def solve(seq):
    divided = list(divide_iter(seq))    
    rewards = list(map(calc_reward, divided))
    costs = list(map(calc_cost, divided))
    max_reward = max(rewards)
    return sum(map(lambda r_c: r_c[1], 
            filter(lambda r_c: r_c[0] == max_reward, zip(rewards, costs))))

def main():
    _ = input()
    A = list(map(int, input().split()))
    print(solve(A))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:

def main():
    num, t = map(int, input().split())
    data = list(map(int, input().split()))

    ans = 1
    min_data = data[0]
    max_sa = 0

    for i in range(1, num):
        now_sa = data[i] - min_data
        if now_sa > max_sa:
           ans = 1
           max_sa = now_sa
        elif now_sa == max_sa:
            ans += 1
        min_data = min(min_data, data[i])

    print(ans)




if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import collections

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

minimum = a[0]
diffs = []
for i in range(1, n):
    diffs.append(a[i] - minimum)
    minimum = min(minimum, a[i])

c = collections.Counter(diffs)
print(c[max(c)])

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(N: int, T: int, A: "List[int]"):
    mx = 0
    mn = float('inf')
    ret = 0
    for a in A:
        if a < mn:
            mn = a
        if a - mn > mx:
            mx = a - mn
            ret = 1
        elif a - mn == mx:
            ret += 1
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    T = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, T, A)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,T = map(int,input().split())
*A, = map(int,input().split())
m = [A[0]]*N
B = [0]*N
for i,a in enumerate(A[1:],1):
    m[i] = min(m[i-1],a)
    B[i] = a - m[i]
MB = max(B)
print(B.count(MB))

Submission status: Accepted

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

ans = 0
tmp_min = A[0]
tmp_diff = 0
for i in range(1, N):
    if A[i] < tmp_min: #今回の値が最小値の時-->最小値を更新する
        tmp_min = A[i]
        continue
    if A[i] - tmp_min == tmp_diff:
        ans += 1
    if A[i] - tmp_min > tmp_diff:
        ans = 1
        tmp_diff = A[i] - tmp_min

print (ans)

Submission status: Accepted

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

max_a = [0]
for i in range(n):
    max_a.append(max(max_a[-1], a[-i - 1]))
max_a.reverse()
profit = []
for i in range(n):
    profit.append(max_a[i] - a[i])
print(profit.count(max(profit)))

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
v = []
currMin = a[0]
for i in range(1, n):
  v.append((currMin, a[i]))
  currMin = min(currMin, a[i])

v = sorted(v, key=lambda x: x[1] - x[0], reverse=True)
cnt = 0
for i in range(len(v)):
  if v[i][1] - v[i][0] == v[0][1] - v[0][0]:
    cnt += 1
print(cnt)

Submission status: Accepted

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

INF = 10 ** 10
min_cum_A = [INF] * N
for i in range(N):
    min_cum_A[i] = min(A[i], min_cum_A[i-1])
ans = 0
max_profit = 0
for i in range(1, N):
    if A[i] - min_cum_A[i-1] > max_profit:
        ans = 1
        max_profit = A[i] - min_cum_A[i-1]
    elif A[i] - min_cum_A[i-1] == max_profit:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

import re
# import numpy as np
# from scipy.misc import perm
# from scipy.misc import comb

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e18)
MOD = int(1e9)+7 # 10^9 + 7

########

N, T = l_inpl()
A = l_inpl()

h = []
min_val = A[0]
for i in range(1, N):
    h.append([A[i], min_val])
    min_val = min(min_val, A[i])

l = [max_val - min_val for max_val, min_val in h]
m = max(l)
print(l.count(m))

Submission status: Accepted

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

m = [A[0]]

mv = A[0]
for a in A[1:] :
    if a < mv :
        m.append(a)
        mv = a
    else :
        m.append(mv)

Md, Mn = 0, 0
for i in range(N - 1, 0, -1) :
    d = A[i] - m[i-1]
    if d > Md :
        Md, Mn = d, 1
    elif d == Md :
        Mn += 1
        
print(Mn)

Submission status: Accepted

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

m = [(A[0], 1)]

mv, mn = A[0], 1
for a in A[1:] :
    if a < mv :
        m.append((a, 1))
        mv, mn = a, 1
    elif a == mv :
        m.append((mv, mn + 1))
        mn += 1
    else :
        m.append((mv, mn))

Md, Mn = 0, 0
for i in range(N - 1, 0, -1) :
    d = A[i] - m[i-1][0]
    if d > Md :
        Md, Mn = d, 1
    elif d == Md :
        Mn += m[i-1][1]
        
print(Mn)

Submission status: Accepted

Solution code:
n, x = [ int(v) for v in input().split() ]

num_list = [ int(v) for v in input().split() ]
profit_list = []

low, high = None, None
for i in range(n):
    if low == None:
        low = num_list[i]
    if high == None:
        high = num_list[i]
    
    if low > num_list[i]:
        if high != low:
            profit_list.append(high-low)
        low, high = num_list[i], num_list[i]
    if num_list[i] > high:
        high = num_list[i]
    if i == n-1 and high != low:
        profit_list.append(high-low)


max_prof = max(profit_list)
ans = profit_list.count(max_prof)
print(ans)