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=[int(i) for i in input().split()]
mn,mx=10**10,-1
d={}
for i in range(n-1):
    mn=min(a[i],mn)
    mx=max(a[i+1]-mn,mx)
    d[a[i]]=i
d[a[n-1]]=n-1
ans=0
for i in range(1,n):
    if a[i]-mx in d and d[a[i]-mx]<i:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18

N, T = list(map(int, sys.stdin.readline().split()))
A = list(map(int, sys.stdin.readline().split()))

cummin = list(itertools.accumulate(A, min))
rcummax = list(reversed(list(itertools.accumulate(reversed(A), max))))

max_profit = 0
for mi, ma in zip(cummin, rcummax):
    max_profit = max(max_profit, ma - mi)

mic = 0
mac = 0
for a, mi, ma in zip(A, cummin, rcummax):
    if a == mi and ma - mi == max_profit:
        mic += 1
    if a == ma and ma - mi == max_profit:
        mac += 1
print(min(mic, mac))

Submission status: Accepted

Solution code:
input()
d,a={},list(map(int,input().split()))
for x in a:
 d[x-a[0]]=d.get(x-a[0],0)+1
 a[0]=min(a[0],x)
print(d[max(d.keys())])

Submission status: Accepted

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

mn = a[0]
d = {}

for x in a:
    d[x-mn] = d.get(x-mn, 0) + 1
    mn = min(mn, x)

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

Submission status: Accepted

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

mn = a[0]
d = {}

for x in a:
    d[x-mn] = d.get(x-mn, 0) + 1
    mn = min(mn, x)

print(max(d.items(), key=lambda x:x[0])[1])

Submission status: Accepted

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

mn = a[0]
l = []

for x in a:
    l.append(x-mn)
    mn = min(mn, x)

l.sort()
print(l.count(l[-1]))

Submission status: Accepted

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 = 0
    if max_bef == tmp:
        cnt += 1
    A_min = min(A_min, A[i])

print(cnt)

Submission status: Accepted

Solution code:
n,t=map(int,input().split())
arr=list(map(int,input().split()))
tmin=10**10
tdiff=0
ans=0
for i in range(n):
  if arr[i]<tmin:
    tmin=arr[i]
  else:
    diff=arr[i]-tmin
    if diff<tdiff:
      continue
    elif tdiff==diff:
      ans+=1
    else:
      tdiff=diff
      ans=1
print(ans)

Submission status: Accepted

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

ma = A[-1]
maL = [ma]
for i in range(1,N):
    if A[-i-1] > ma:
        ma = A[-i-1]
        maL.append(ma)
    else:
        maL.append(ma)

ans = 1
maL = maL[::-1]
sa = maL[0] - A[0]
for i in range(1,N):
    s = maL[i] - A[i]
    if s == sa:
        ans += 1
    elif s > sa:
        ans = 1
        sa = s
print(ans)

Submission status: Accepted

Solution code:
#coding:utf-8
N,T=map(int,raw_input().split())
A=map(int,raw_input().split())
A.reverse()
ma=-1
B=[-1145181919810]*N
for i in range(len(A)):
    if ma<A[i]:ma=A[i]
    else:B[i]=ma-A[i]
mi=max(B)
ans=0
for b in B:
    if b==mi:ans+=1
print(ans)

Submission status: Accepted

Solution code:
n,t=map(int,input().split())
a=list(map(int,input().split()))
ma=[0]*n
ma[n-1]=a[n-1]
for i in range(n-2,-1,-1):
  ma[i]=max(ma[i+1],a[i])
plus=[0]*n
for j in range(n):
  plus[j]=ma[j]-a[j]
plusm=max(plus)
print(plus.count(plusm))

Submission status: Accepted

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 = -mod

for i in range(1,N):
    if dif < R_max[i] - L_min[i] and 0 < 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: Accepted

Solution code:
s=input()
a=list(map(int,input().split()))
mx=0
l=[]
for i in a[::-1]:
    mx = max(mx,i)
    l+=[mx-i]
l.sort()
r = 0
for i in l[::-1]:
    if i==l[-1]:
        r+=1
print(r)

Submission status: Accepted

Solution code:
n , t = map(int,input().split())
a = list(map(int,input().split()))
mx = 0
l = []
for i in a[::-1]:
    mx = max(mx,i)
    l.append(mx-i)
l.sort()
res = 0
for i in l[::-1]:
    if i==l[-1]:
        res+=1
    else:
        break
print(res)

Submission status: Accepted

Solution code:
N,T=map(int,input().split())
A=list(map(int,input().split()))
d=0
m=A[0]
M=A[0]
for i in range(N):
    if m>A[i]:
        m=A[i]
        M=A[i]
    elif M<A[i]:
        M=A[i]
        d=max(M-m,d)
tmp=0
D=0
m=A[0]
M=A[0]
for i in range(N):
    if m>A[i]:
        m=A[i]
        M=A[i]
    elif M<A[i]:
        M=A[i]
        D=max(M-m,D)
        if M-m==d:
            tmp+=1
print(tmp)

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

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

Submission status: Accepted

Solution code:
n, t = map(int, input().split())
a = list(map(int, input().split()))
a_min = a[0]
d = 0
x = 0
for i in range(1, n):
    di = a[i] - a_min
    if d < di:
        d = di
        x = 1
    elif d == di:
        x += 1
    a_min = min(a_min, a[i])
print(x)

Submission status: Accepted

Solution code:
N,M = [ int(it) for it in input().split() ]
li = [ int(it) for it in input().split() ]
limax = [ it for it in li ]
for i in range(N-2,-1,-1):
  limax[i] = max(limax[i+1],li[i])
ma = -100000000000000000000
for i in range(N-1,-1,-1):
  ma=max(limax[i] - li[i],ma)
s = 0
for i in range(N-1,-1,-1):
  if (limax[i] - li[i]==ma):
    s+=1
print ( s )

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
A = [int(a) for a in input().split()]
mi = 10**9
madif = 0
madifcnt = 0
for a in A:
    if a < mi:
        mi = a
    elif a - mi > madif:
        madif = a - mi
        madifcnt = 1
    elif a - mi == madif:
        madifcnt += 1

print(madifcnt)

Submission status: Accepted

Solution code:
n, t = map(int, input().split())
a = list(map(int, input().split()))
max_a = 0
profit = 0
ans = 0
for i in range(n)[::-1]:
    max_a = max(max_a, a[i])
    tmp_profit = max_a - a[i]
    if tmp_profit > profit:
        profit = tmp_profit
        ans = 1
    elif tmp_profit == profit:
        ans += 1
print(ans)

Submission status: Accepted

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

A_MIN = list(accumulate(A, func=min))
diff = [a - a_min for a, a_min in zip(A, A_MIN)]

MAX_diff = max(diff)
print(diff.count(MAX_diff))

Submission status: Accepted

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

Submission status: Accepted

Solution code:


def read_input():
    n, t = map(int, input().split())
    alist = list(map(int, input().split()))

    return n, t, alist


def submit():
    n, t, alist = read_input()

    takahashi_cap = [0]
    curr_min = alist[0]

    for i in range(1, n):
        a = alist[i]
        takahashi_cap.append(a - curr_min)
        if a < curr_min:
            curr_min = a

    takahashi_max = max(takahashi_cap)
    print(len([t for t in takahashi_cap if t == takahashi_max]))


if __name__ == '__main__':
    submit()

Submission status: Accepted

Solution code:
inf = 10**18
mod = 10**9+7

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

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

max_now = 0
max_idx = 0
max_gap = 0
dat = []
for i in range(n-1,-1,-1):
    if i == n-1:
        max_now = a[i]
        max_idx = i
        max_gap = 0
    else:
        if a[i]>max_now:
            max_idx = i
            max_now = a[i]
            dat.append((a[i],i,max_now,max_idx,0))
        else:
            dat.append((a[i],i,max_now,max_idx,max_now-a[i]))
dat.sort(key = lambda x:x[4],reverse=True)
max_gap = dat[0][4]

res = 0
for _,_,_,_,gap in dat:
    if gap == max_gap:
        res+=1
    else:
        break
print(res)

Submission status: Accepted

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

prof = 0
_min = A[0]
setA = set()
answer = 0

for a in A:
  setA.add(a)
  if a > prof+_min:
    prof = a-_min
    answer = 1
    continue
  if _min < a <= prof+_min:
    if a-prof in setA:
      answer +=1    
    continue
  if a<_min:
    _min = a
    continue
    
print(answer)

Submission status: Accepted

Solution code:
n,t=map(int,input().split())
a=[int(i) for i in input().split()]
p=a[0]
l=[]
for i in range(n):
    p=min(p,a[i])
    if a[i]-p>0:
        l.append(a[i]-p)

print(l.count(max(l)))

Submission status: Accepted

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

B = [A[0]]
for i in range(1, N):
    if A[i] < B[-1]:
        B.append(A[i])
    else:
        B.append(B[-1])
        
A.reverse()
C = [A[0]]
for i in range(1, N):
    if A[i] > C[-1]:
        C.append(A[i])
    else:
        C.append(C[-1])
C.reverse()

ans = [[C[1] - B[0]]]
for i in range(1, N - 1):
    if B[i] < B[i - 1]:
        ans.append([C[i + 1] - B[i]])
        
x = max(ans)
print(ans.count(x))

Submission status: Accepted

Solution code:
import sys
from collections import deque

def main():
    input = sys.stdin.readline
    N, T = map(int, input().split())
    A = list(map(int, input().split()))
    B = [0 for _ in range(N)]

    a = A[0]
    max_profit = 0
    for i in range(N):
        a = min(a, A[i])
        B[i] = A[i] - a
        max_profit = max(max_profit, A[i] - a)

    cnt = 0
    for b in B:
        if b == max_profit:
            cnt += 1

    return cnt


if __name__ == '__main__':
    print(main())

Submission status: Accepted

Solution code:
n, t = [int(item) for item in input().split()]
a = [int(item) for item in input().split()]

min_rate = a[0]
max_diff = 0
for item in a[1:]:
    if item < min_rate:
        min_rate = item
    else:
        max_diff = max(max_diff, item-min_rate)

min_rate = a[0]
problems = []
to_solve = [0]
has_problem = False
for item in a[1:]:
    if item < min_rate:
        min_rate = item
        if has_problem:
            problems.append(to_solve)
        to_solve = [0]
        has_problem = False
    elif item == min_rate:
        to_solve.append(0)
    elif item == min_rate + max_diff:
        to_solve.append(1)
        has_problem = True 
if has_problem:
    problems.append(to_solve)
print(len(problems))

Submission status: Accepted

Solution code:
def solve():
  n,t = (int(i) for i in input().split())
  a = list(int(i) for i in input().split())
  query = [-1]
  querymax = -1
  minA = a[0]
  for i in range(1,n):
    if minA < a[i]:
      if querymax <= a[i]-minA:
        querymax = a[i]-minA
        query.append(a[i]-minA)
    
    
    minA = min(minA,a[i])
  print(query.count(max(query)))
    
solve()

Submission status: Accepted

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

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

apple_price = list(map(int, input().split()))
price_diff = []
now_min = 10**9


for i in range(n):
    if(now_min > apple_price[i]):
        now_min = apple_price[i]
    else:
        price_diff.append(apple_price[i] - now_min)

if(price_diff):
    print(price_diff.count(max(price_diff)))
else:
    print(0)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, T = MAP()
A = LIST()
# B = [max(A[i+1:N])-A[i] for i in range(N-1)] # O(N^2)時間かかる
# print(B)
min_ = INF
B = []
for i in A:
	B.append(i-min_)
	# print(min_)
	if min_ > i:
		min_ = i
# print(B)
print(B.count(max(B)))

Submission status: Accepted

Solution code:
def an_invisible_hand(N: int, T: int, A: list) -> int:
    max_profit = 0
    max_profit_pair_num = 0
    min_price = A[0]

    for price in A[1:]:
        # 今まで訪れた街の中で最安値で買えるところで買えるだけ
        # 買って今いる街で全て売ると仮定して利益を算出
        profit = price - min_price

        if max_profit < profit:
            # 利益の最大値を更新できるなら更新する。
            max_profit = profit
            max_profit_pair_num = 1
        elif max_profit == profit:
            # 最大利益を出せる街のペアに対して操作を
            # 行うので、その数を保持する。
            max_profit_pair_num += 1

        min_price = min(min_price, price)

    # 最大利益を出せる街のペアに対して、最高値を 1 下げるか最安値を 1 あげるか
    # すれば利益を 1 円減らせる。ただ、一つのペアを変更してもそのほかのペアが残
    # っていればそのペアを利用して最高利益をあげられるので全ペアに同じ操作が必要
    # 。結局、最大利益をあげるペアの数が最小操作回数で、それらに 1 の変化を与え
    # れば良いので最小コストでもある。
    return max_profit_pair_num


if __name__ == "__main__":
    N, T = map(int, input().split())
    A = [int(s) for s in input().split()]
    ans = an_invisible_hand(N, T, A)
    print(ans)

Submission status: Accepted

Solution code:
from functools import reduce

def main():
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10
    
    # 1文字のみを読み込み
    # s = input().rstrip()
    
    # スペース区切りで標準入力を配列として読み込み
    # s = input().rstrip().split(' ')

    # 1文字ずつ標準入力を配列として読み込み
    # s = list(input().rstrip())
    # N, A = [int(_) for _ in input().split()]
    # X = [int(_) for _ in input().split()]
    s = input().rstrip().split(' ')
    N = int(s[0])
    T = int(s[1])
    A = [int(_) for _ in input().split()]
    min_a = A[0]
    max_cost = 0
    ans = 0
    for a in A:
        if(min_a > a):
            min_a = a
        if(a-min_a > max_cost):
            max_cost = a-min_a
            ans = 1
        elif(a-min_a == max_cost):
            ans = ans + 1
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,t=map(int,input().split())
a=list(map(int,input().split()))
d=[]
l=0
for i in range(n-1,0,-1):
    l=max(l,a[i])
    d.append(l)
d=d[::-1]
h=0
k=0
for i in range(n-1):
    if a[i]-d[i]==h:
        k+=1
    elif a[i]-d[i]<h:
        h=a[i]-d[i]
        k=1
print(k)

Submission status: Accepted

Solution code:
n,t=[int(_) for _ in input().split(" ")]
a=[int(_) for _ in input().split(" ")]
b,m=[],a[0]
for _ in a:
  b.append(m)
  m=min(m,_)
d={}
for _a,_m in zip(a,b):
  if (_a-_m) in d:
    d[_a-_m]+=1
  else:
    d[_a-_m]=1

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

Submission status: Accepted

Solution code:
def main():
    N, T = map(int, input().split())
    A = list(map(int, input().split()))
    minimum = float("inf")
    maximum = -1
    ans = 0
    for i in range(N):
        minimum = min(A[i], minimum)
        if maximum == A[i] - minimum:
            ans += 1
        elif maximum < A[i] - minimum:
            maximum = A[i] - minimum
            ans = 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
x = list(map(int,input().split()))

x = x[::-1]
d = dict()
m = x.pop()
M = -1
while x:
    t = x.pop()
    if M < t-m:
        M = t-m
        d[M] = 1
    elif M == t-m:
        d[M] +=1
    m = min(m,t)
print(d[M])

Submission status: Accepted

Solution code:
n,_ = map(int, input().split())
rate = list(map(int, input().split()))
rmax = [rate[-1]]*n
for i in range(n-2,-1,-1):
  rmax[i] = max(rmax[i+1],rate[i])
benemax = 0
cnt = 0
for i in range(n-1):
  newr = rmax[i]-rate[i]
  if newr > benemax:
    benemax = newr
    cnt = 1
  elif newr == benemax:
    cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
A = list(map(int, input().split()))
M, m, ans = 0, A[0], 0
for i in range(1, N):
    if M < A[i] - m:
        M = A[i] - m
        ans = 1
    elif M == A[i] - m:
        ans += 1
    if A[i] < m:
        m = A[i]
print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import deque
import copy
import math
import heapq
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, T] = [int(input_raw[0]), int(input_raw[0])]
    input_raw = read_func().strip().split()
    A = [int(input_raw[i]) for i in range(N)]
    que = [-A[N - 1]]
    max_sub = 0
    count = 0
    for i in range(N-2, -1, -1):
        if (-que[0]) - A[i] == max_sub:
            count += 1
        elif (-que[0]) - A[i] > max_sub:
            count = 1
            max_sub = max((-que[0]) - A[i], max_sub)
        heapq.heappush(que, -A[i])
    print min(count, T/2)




if __name__ == '__main__':
    main()

Submission status: Accepted

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

m = a[0]
d = 0
c = 1

for i in range(1, n):
    if a[i] - m > d:
        d = a[i] - m
        c = 1
    elif a[i] - m == d:
        c += 1
    elif a[i] < m:
        m = a[i]

print(c)

Submission status: Accepted

Solution code:
N,T = map(int,input().split())
A = list(map(int,input().split()))
minkouho = A[0]
curmin = 0
num = 0
for i in range(1,N):
  minkouho = min(minkouho,A[i-1])
  if A[i] - minkouho >= 0:
    if A[i] - minkouho > curmin:
      num = 1
      curmin = A[i]-minkouho
    elif A[i] - minkouho == curmin:
      num += 1
print(num)

Submission status: Accepted

Solution code:
#ABC047D
N,T=map(int,input().split())
A=list(map(int,input().split()))
ma=0
mi=10**9+1
dif=0
c=0
for a in A:
	if a<mi:
		mi=a
	else: #mi<a
		if ma<a: #mi<ma<a
			ma=a
			dif=ma-mi
			c=1
		else: #mi<a<ma
			if dif==a-mi:
				c+=1
			elif dif<a-mi:
				dif=a-mi
	
print(c)

Submission status: Accepted

Solution code:
import sys
N,T = [int(n) for n in input().split()]
# N = int(input())
A = [int(n) for n in input().split()]

minv = 10**10
difmax = 0
ans = 0
for i in range(N):
    minv = min(minv,A[i])
    if(difmax < A[i]-minv):
        difmax = A[i]-minv
        ans = 1
    elif difmax == A[i]-minv:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
n,t=map(int,input().split())
a=list(map(int,input().split()))
from collections import defaultdict
ans = defaultdict(int)
nowmin=1+10**9
nowmax=0
for i in range(n):
    if a[i]<nowmin:
        nowmin=a[i]
    if a[i]>nowmin:
        profit=a[i]-nowmin
        ans[profit]+=1
        if profit>nowmax:nowmax=profit
print(ans[nowmax])

Submission status: Accepted

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

max_profit = 0
ans = 1
left = 0
right = 1

min_a = a[0]
for i in range(1, N):
    if min_a < a[i]:
        profit = a[i] - min_a
        if profit == max_profit:
            ans += 1
        else:
            max_profit = max(max_profit, profit)
    else:
        min_a = min(min_a, a[i])

print(ans)

Submission status: Accepted

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

max_profit = 0
ans = 1
left = 0
right = 1

while right < N:
    if a[left] < a[right]:
        profit = a[right] - a[left]
        if profit == max_profit:
            ans += 1
        else:
            max_profit = max(max_profit, profit)
    else:
        left = right
    right += 1

print(ans)

Submission status: Accepted

Solution code:
def getN():
    return int(input())

def getMN():
    a = input().split()
    b = [int(i) for i in a]
    return b[0],b[1]

def getlist():
    a = input().split()
    b = [int(i) for i in a]
    return b

from collections import defaultdict

n, t = getMN()
nums = getlist()
ans = defaultdict(int)
cur = nums[0]
upper = cur
profits = defaultdict(int)
n_low = 1
n_up = 1

for num in nums[1:]:
    if cur > num:
        profits[upper-cur] += min(n_low, n_up)
        cur = num
        n_low = 1
        n_up = 1
        upper = cur
    elif cur == num:
        n_low += 1
    elif num == upper:
        n_up += 1
    elif num > upper:
        upper = num
        n_up = 1
profits[upper-cur] += min(n_low, n_up)

maxkey = max(profits.keys())
print(profits[maxkey])

Submission status: Accepted

Solution code:
def getN():
    return int(input())

def getMN():
    a = input().split()
    b = [int(i) for i in a]
    return b[0],b[1]

def getlist():
    a = input().split()
    b = [int(i) for i in a]
    return b

from collections import defaultdict

n, t = getMN()
nums = getlist()
ans = defaultdict(int)
cur = nums[0]
upper = cur
profits = defaultdict(int)
n_low = 1
n_up = 1

for num in nums[1:]:
    if cur > num:
        profits[upper-cur] += min(n_low, n_up)
        cur = num
        n_low = 1
        n_up = 1
        upper = cur
    elif cur == num:
        n_low += 1
    elif num == upper:
        n_up += 1
    elif num > upper:
        upper = num
        n_up = 1
profits[upper-cur] += min(n_low, n_up)

maxkey = max(profits.keys())
print(profits[maxkey])

Submission status: Accepted

Solution code:
from collections import defaultdict
N, T = map( int, input().split())
A = list( map( int, input().split()))
now = A[0]
c = 0
for i in range(N):
    c = max( c, A[i]-now)
    now = min( now, A[i])
d = defaultdict( lambda :-1)
for i in range(N):
    d[A[i]] = i
ans = 0
for i in range(N):
    if d[A[i]+c] == -1:
        continue
    if d[A[i]+c] > i:
        ans += 1
print( ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

m=[None]*n
used=[False]*n

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

c=Counter([m[i]-a[i] for i in range(n)])
print(c[max(c.keys())])

Submission status: Accepted

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

mina = a[0]
minac = 1
maxd = 0
maxdc = 1
for i in range(1, n):
    if a[i] < mina:
        mina = a[i]
        minac = 1
    elif a[i] == mina:
        minac += 1
    elif a[i] - mina > maxd:
        maxd = a[i] - mina
        maxdc = 1
    elif a[i] - mina == maxd:
        maxdc += 1
print(maxdc)

Submission status: Accepted

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

"""
参考：https://atcoder.jp/contests/abc047/submissions/4077573
"""

import sys
def input(): return sys.stdin.readline().strip()
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, T = MAP()
aN = LIST()

mx = -INF
l = aN[0]
cnt = 0
for i in range(1,N):
    # 最低値更新なら始点を動かす
    if aN[i] < l:
        l = aN[i]
    else:
        # 最高値更新ならその場所が操作対象になる
        if aN[i] - l > mx:
            mx = aN[i] - l
            cnt = 1
        # 同率最高値なら操作対象が1つ増える
        elif aN[i] - l == mx:
            cnt += 1
print(cnt)

Submission status: Accepted

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

"""
参考：https://atcoder.jp/contests/abc047/submissions/4077573
"""

import sys
import re
from collections import deque, Counter, defaultdict
from math import sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, product, combinations, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, T = MAP()
aN = LIST()

mx = -INF
l = aN[0]
cnt = 0
for i in range(1,N):
    # 最低値更新なら始点を動かす
    if aN[i] < l:
        l = aN[i]
    else:
        # 最高値更新ならその場所が操作対象になる
        if aN[i] - l > mx:
            mx = aN[i] - l
            cnt = 1
        # 同率最高値なら操作対象が1つ増える
        elif aN[i] - l == mx:
            cnt += 1
print(cnt)

Submission status: Accepted

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

import sys
import re
from collections import deque, Counter, defaultdict
from math import sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, product, combinations, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, T = MAP()
aN = LIST()

mx = -INF
l, r = 0, 1
cnt = 0
# 外ループで左を動かす
while l < N:
    # 内ループは条件を満たす限り右を動かす
    while r < N and aN[l] < aN[r]:
        # 最高値更新ならその場所が操作対象になる
        if aN[r] - aN[l] > mx:
            mx = aN[r] - aN[l]
            cnt = 1
        # 同率最高値なら操作対象が1つ増える
        elif aN[r] - aN[l] == mx:
            cnt += 1
        mx = max(aN[r] - aN[l], mx)
        r += 1
    # 左端を右端に追いつかせる
    l = r
    r += 1
print(cnt)

Submission status: Accepted

Solution code:
n,t=map(int,input().split())
a=list(map(int,input().split()))
saisyo=a[0]
saidai=0
count=0
for i in range(n):
    if a[i]<saisyo:saisyo=a[i]
    else:
        if a[i]-saisyo>saidai:
            saidai=a[i]-saisyo
            count=1
        elif a[i]-saisyo==saidai:
            count+=1
print(count)

Submission status: Accepted

Solution code:
indexes = []


def dfs(Ds, s, e, v=None):
    if e - s == 1:
        if v == Ds[s]:
            indexes.append((s, e))
        return Ds[s]
    else:
        center = (s + e) // 2
        left = dfs(Ds, s, center, v=v)
        right = dfs(Ds, center, e, v=v)

        left_m = - (10 ** 9)
        li = -1
        su = 0
        for i in range(center-1, s-1, -1):
            su += Ds[i]
            if left_m != max(left_m, su):
                left_m = max(left_m, su)
                li = i

        right_m = -(10 ** 9)
        ri = -1
        su = 0
        for i in range(center, e):
            su += Ds[i]
            if right_m != max(right_m, su):
                right_m = max(right_m, su)
                ri = i

        if left_m + right_m == v:
            indexes.append((li, ri))

        m = max(left, right, left_m + right_m)
        return m


def solve(N, T, As):
    Ds = [As[i + 1] - As[i] for i in range(N - 1)]
    max_v = dfs(Ds, 0, N - 1)
    dfs(Ds, 0, N - 1, v=max_v)
    return len(indexes)


if __name__ == "__main__":
    N, T = map(int, input().split(" "))
    As = list(map(int, input().split(" ")))
    print(solve(N, T, As))

Submission status: Accepted

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


def main():
    from collections import Counter

    n, t = map(int, input().split())
    a = list(map(int, input().split()))
    minmum_numbers = [a[0] for _ in range(n)]
    diff = [0 for _ in range(n)]

    for i in range(1, n):
        minmum_numbers[i] = min(minmum_numbers[i - 1], a[i])
        diff[i] = a[i] - minmum_numbers[i]

    print(sorted(Counter(diff).items(), key=lambda x: x[0], reverse=True)[0][1])


if __name__ == '__main__':
    main()