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

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

profit = -1
low = a[0]
for i in range(n):
    if a[i] < low:
        low = a[i]
    x = 0 if low > a[i] else a[i] - low
    if profit < x:
        profit = x

ans = 0
diff = 0
for i in range(n - 1):
    if a[i] > a[i + 1]:
        diff = 0
    else:
        diff += a[i + 1] - a[i]
    if diff == profit:
        ans += 1

print(ans)

Submission status: Wrong Answer

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

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


max_d = 0
max_count = 0

current_min = 9999999
current_max = 0

for a in A:
    if a < current_min:
        current_min = a
        current_max = 0
        if max_d < (current_max - current_min):
            max_d = current_max - current_min
            max_count = 1
        elif max_d == (current_max - current_min):
            max_count += 1

    if a > current_max:
        current_max = a
        if max_d < (current_max - current_min):
            max_d = current_max - current_min
            max_count = 1
        elif max_d == (current_max - current_min):
            max_count += 1

print(max_count)

Submission status: Wrong Answer

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

check = l[0]
count = 0
dis = 0
for i in l:
    if i < check:
        check = i
        ans += [dis]*count
        count = 0
        dis = 0
    elif i == check:
        count += 1
    else:
        dis = i-check
        ans.append(dis)
print(ans.count(max(ans)))

Submission status: Wrong Answer

Solution code:
n, k, *a = map(int, open(0).read().split())

mx, mn = 0, 1e18
ans = tmp = 0
got = 1
for i in range(n):
    mx = max(mx, a[i])
    if(mn>a[i]): mn = mx = a[i]
    if got==mx-mn:
        tmp += 1
    elif got<mx-mn:
        got = mx-mn
        tmp = 1
    ans = max(ans, tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
n, k, *a = map(int, open(0).read().split())

mx, mn = 0, 1e18
ans, got = 1, 0
for i in range(n):
    mx = max(mx, a[i])
    if(mn>a[i]): mn = mx = a[i]
    elif got==mx-mn: ans += 1
    elif got<mx-mn:
        got = mx-mn
        ans = 1
print(ans)

Submission status: Wrong Answer

Solution code:
n, k, *a = map(int, open(0).read().split())

mx, mn = 0, 1e18
ans, got = 1, 0
for i in range(n):
    mx = max(mx, a[i])
    if(mn>a[i]): mn = mx = a[i]
    if got==mx-mn: ans += 1
    elif got<mx-mn:
        got = mx-mn
        ans = 1
print(ans)

Submission status: Wrong Answer

Solution code:
n, k, *a = map(int, open(0).read().split())

mx, mn = 0, 1e11
ans, got = 1, -1
for i in range(n):
    mx = max(mx, a[i])
    if(mn>a[i]): mn = mx = a[i]
    if got==mx-mn: ans += 1
    elif got<mx-mn:
        got = mx-mn
        ans = 1
print(ans)

Submission status: Wrong Answer

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

diff = []

tmp = a[0]
chk = 0

for i in range(1,n):
    if a[i] > tmp:
        chk += a[i] - tmp
        tmp = a[i]
    else:
        diff.append(chk)
        chk = 0
        tmp = a[i]
    if i == n-1 and chk > 0:
        diff.append(chk)

print(diff.count(max(diff)))

Submission status: Wrong Answer

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


import heapq
import collections
hq=[]
heapq.heapify(hq)
heapq.heappush(hq,A[0])
tmp=0
table=collections.defaultdict(int)
for i in range(N-1):
  j=heapq.heappop(hq)
  table[A[i]-j]+=1
  tmp=max(tmp,A[i]-j)
  heapq.heappush(hq,j)
  heapq.heappush(hq,A[i])
print(table[tmp])

Submission status: Wrong Answer

Solution code:
N, T = map(int, input().split())
A = list(map(int, input().split()))
T -= T%2
start = A[0]
D = []
for i in range(N-1):
    if A[i] < A[i+1]:
        if i == N-2:
            D.append(A[-1]-start)
        else:
            continue
    else:
        D.append(A[i]-start)
        start = A[i+1]

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

Submission status: Wrong Answer

Solution code:
n,t=map(int,input().split())
a=list(map(int,input().split()))
b=[a[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: Wrong Answer

Solution code:
def read_values():
    return map(int, input().split())


def read_list():
    return list(map(int, input().split()))


def main():
    N, T = read_values()
    A = read_list()

    l = A[0]
    p = 0
    D = {}
    for a in A:
        if p > a:
            D[p - l] = D.setdefault(p - l, 0) + 1
            l = a
        p = a
    D[p - l] = D.setdefault(p - l, 0) + 1

    k = max(D.keys())
    print(D[k])


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

n, t = map(int,input().split())
a = list(map(int,input().split()))
b = []
m = 0
for i in range(n-1):
    if a[i+1]-a[i] > 0:
        m += a[i+1]-a[i]
    else:
        b.append(m)
        m = 0
b.append(m)
b.sort(reverse=True)
c = 1
for i in range(1,len(b)-1):
    if b[0] == b[i]:
        c += 1
    else:
        break
print(c)

Submission status: Wrong Answer

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

TT=T//2

max=N-1
low=0
maxnum=0
dif = -1

for i in range(1,len(A)):
    if(A[low]>A[i]):
        low=i
    else:
        if(A[i] - A[low] > dif):
            dif=A[i] - A[low]
            maxnum=1
        elif(dif==A[i] - A[low]):
            maxnum+=1

print(min(maxnum,TT))

Submission status: Wrong Answer

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

TT=T//2

max=0
low=A[0]
maxnum=0
dif = -1

for i in range(1,len(A)):
    if(low>A[i]):
        low=A[i]
    else:
        if(A[i] - low > max):
            max=A[i] - low
            maxnum=1
            dif=0
        elif(max==A[i] - low):
            maxnum+=1

print(min(maxnum,TT))

Submission status: Wrong Answer

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

TT=T//2

max=0
low=A[0]
maxnum=0
dif = -1

for i in range(1,len(A)):
    if(low>A[i]):
        low=A[i]

    if(A[i] - low > max):
        max=A[i] - low
        maxnum=1
        dif=0
    elif(max==A[i] - low):
        maxnum+=1

print(min(maxnum,TT))

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

#入力
N,T=[int(x) for x in input().split()]
A=[int(x) for x in input().split()]

TT=T//2

max=0
low=10**9 + 1
maxnum=0
dif = 0

for i in range(len(A)):
    if(low>A[i]):
        low=A[i]

    if(A[i] - low > max):
        max=A[i] - low
        maxnum=1
        dif=0
    elif(max==A[i] - low):
        maxnum+=1

print(min(maxnum,TT))

Submission status: Wrong Answer

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


rieki=0
count=0
for ind,i in enumerate(A):
    lst=A[:ind+1]
    if(ind==len(A)-1):
        break
    elif(A[ind+1]-min(lst) >= rieki):
        rieki=A[ind+1]-min(lst)
        count=1
    elif(A[ind+1]-min(lst) == rieki):
        count+=1


print(count)

Submission status: Wrong Answer

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("L[i]:{0}, min:{1}, max:{2}, subt:{3}, count:{4}".format(L[i], minvalue, maxvalue, subt, count))

print(count)

Submission status: Wrong Answer

Solution code:
import copy

n, t = map(int, input().split())
L = [int(i) for i in input().split()]
LL = copy.deepcopy(L)
LL.sort()

print(LL)

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

print(count)

Submission status: Wrong Answer

Solution code:
import copy

n, t = map(int, input().split())
L = [int(i) for i in input().split()]
LL = copy.deepcopy(L)
LL.sort()

print(LL)

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

print(count)

Submission status: Wrong Answer

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

sa=[]
for i in range(n):
  for j in range(i+1,n):
    sa.append(max(A[i:j+1])-min(A[i:j+1]))
ans=0
maxi=0
for i in range(1,len(sa)):
  if maxi==sa[i]-sa[i-1]:
    ans+=1
  elif maxi<sa[i]-sa[i-1]:
    ans=1
    maxi=max(maxi,sa[i]-sa[i-1])
print(ans)

Submission status: Wrong Answer

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])
    if min_a>=a[i]:continue
    c=a[i]-min_a
    cost[c]=cost.get(c,0)+1
print(max(cost.values()))

Submission status: Wrong Answer

Solution code:
n, t = map(int, input().split())
ls = list(map(int, input().split()))
ms = []
m = ls[-1]
for x in ls[1::-1]:
    ms.append(max(m, x))
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: Wrong Answer

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

for i in range(len(A)) :
    if i == 0 :
        mi = A[i]
    elif i == N-1 and A[i]-mi > 0 :
        d.append(A[i]-mi)
    elif A[i]-A[i-1] < 0 :
        d.append(A[i-1]-mi)
        mi = A[i]

print(d.count(max(d)))

Submission status: Wrong Answer

Solution code:
N,T = map(int,input().split())
A = list(map(int,input().split())) + [-1]

d = []

mi = A[0]
ma = A[0]

for i in range(1, len(A)) :
    ai = A[i]
    if ma < ai :
        ma = ai
    else :
        d.append(ma-mi)
        mi = ai
        ma = ai

ans = d.count(max(d))

print(ans)

Submission status: Wrong Answer

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

mi = -1
ma = -1
d = 0
cnt = 0
ans = 0

mi = A[0]
ma = A[0]

for i in range(1, N) :
    ai = A[i]
    if ma < ai :
        ma = ai
    else :
        if d == ma-mi :
            cnt += 1
        elif d < ma-mi :
            ans = max(ans, cnt)
            cnt = 1
            d = ma-mi
        mi = ai
        ma = ai

ans = max(ans, cnt)
print(ans)

Submission status: Wrong Answer

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:
    print(maxval)
    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: Wrong Answer

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

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

ans = 0
flag = 0

for i in range(n):

    if a[i] - m[i] == flag:
        ans += 1
    if a[i] - m[i] > flag:
        flag = a[i] - m[i]
        ans = 1


print(ans)

Submission status: Wrong Answer

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

flag = 0

v=[]
for i in range(n):
    # print(i, flag, a[i], a[i + 1])
    if a[i] > a[i + 1]:
        v.append(a[i] - a[flag])
        flag = i + 1
# print(v)

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

Submission status: Wrong Answer

Solution code:
_,_,*a=map(int,open(0).read().split());d={}
for x,y in zip(a,__import__("itertools").accumulate(a,min)):d[x-y]=d.get(x-y,0)+1
print(list(d.values())[-1])

Submission status: Wrong Answer

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(min(cnt, T//2))

Submission status: Wrong Answer

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

if max_count * 2 <= T:
    print(max_count)
else:
    print(T // 2)

Submission status: Wrong Answer

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

if max_count * 2 >= T:
    print(max_count)
else:
    print(T // 2)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

N, T = map(int, input().split())
l = list(map(int, input().split()))
sagaku_l = []
kouhomati = []
for i in range(N):
    for j in range(N - i - 1):
        sagaku = l[i + j + 1] - l[i]
        if sagaku > 0:
            sagaku_l.append([i, i + j + 1, sagaku])

# sagaku_max = max(zip(*sagaku_l))[0]
sagaku_l.sort(key=itemgetter(2), reverse=True)
print(sagaku_l)
print(len(sagaku_l))
for k in range(len(sagaku_l)):
    if sagaku_l[0][2] != sagaku_l[k][2]:
        break
    if not sagaku_l[k][0] in kouhomati:
        kouhomati.append(sagaku_l[k][0])
    if not sagaku_l[k][1] in kouhomati:
        kouhomati.append(sagaku_l[k][1])
print(len(kouhomati)/2)

Submission status: Wrong Answer

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):
    B[i-1] = A[i] - minA
    if A[i] < minA:
        minA = A[i]
B.sort(reverse=True)
ans = 0
for i in B:
    if i == B[0]:
        ans += 1
    else:
        print(ans)
        break

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

profit_list = []

small_idx = 0

for i in range(N):
    if i == N-1:
        big_idx = i
        profit_list.append(a_list[big_idx]-a_list[small_idx])
    elif a_list[i] > a_list[i+1]:
        big_idx = i
        profit_list.append(a_list[big_idx]-a_list[small_idx])
        small_idx = i+1

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

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

Submission status: Wrong Answer

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

amin=10**9
amax=10**9
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
    
print(dacount)

Submission status: Wrong Answer

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

amin=A[0]
amax=A[0]
damax=0
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
    
print(dacount)

Submission status: Wrong Answer

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

    if a[i] < Min:
        if dif == Max - Min:
            ans += 1
        if dif < Max - Min:
            ans = 1
            dif = Max - Min
        Min = a[i]
        Max = a[i]

print(ans)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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


criticalnumberlist=[0]
for i in range(N-1):
    if A[i] > A[i+1]:
        criticalnumberlist.append(i+1)
criticalnumberlist.append(N)

maxdiff = 0
ct = 0
for j in range(len(criticalnumberlist)-1):
    currentdiff = A[criticalnumberlist[j]:criticalnumberlist[j+1]][-1] - A[criticalnumberlist[j]:criticalnumberlist[j+1]][0]
    if currentdiff > maxdiff:
        maxdiff =currentdiff
        ct = 1
    elif currentdiff == maxdiff:
        ct += 1

print(ct)

Submission status: Wrong Answer

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()))
m = 0
r = 0
for l in range(n):
    tmp = a[l]
    while r < n:
        if tmp <= a[r]:
            tmp = a[r]
            m = max(m,a[r]-a[l])
            r += 1
        else:
            break

r = 0
ans = 0
for l in range(n):
    tmp = a[l]
    while r < n:
        if tmp <= a[r]:
            tmp = a[r]
            if a[r]-a[l] == m:
                ans += 1
            r += 1
        else:
            break
print(ans)

Submission status: Wrong Answer

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()))
m = 0
r = 0
for l in range(n):
    tmp = a[l]
    while r < n:
        if tmp <= a[r]:
            tmp = a[r]
        else:
            break
        m = max(m,a[r]-a[l])
        r += 1
    l = r

r = 0
ans = 0
for l in range(n):
    tmp = a[l]
    while r < n:
        if tmp <= a[r]:
            tmp = a[r]
        else:
            break
        if a[r]-a[l] == m:
            ans += 1
        r += 1
    l = r
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
v = []
currMin = k
for i in range(n):
  v.append((a[i], currMin))
  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: Wrong Answer

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((a[i], currMin))
  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: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
v = []
i = 0
while i < len(a):
  if i == len(a) - 1 or a[i] > a[i + 1]:
    i = i + 1
    continue
  j = i
  while j + 1 < len(a) and a[j + 1] > a[j]:
    j += 1
  v.append((a[i], a[j]))
  i = j + 1

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

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, key=d.get))

Submission status: Wrong Answer

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

mn = a[0]
d = {0: 1}

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

print(max(d.values()))

Submission status: Wrong Answer

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

mn = a[0]
d = {}

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

print(max(d.values()))

Submission status: Wrong Answer

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

mn = a[0]
d = {}

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

print(max(d.values()))

Submission status: Wrong Answer

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

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 = 0
maL = maL[::-1]
print(maL)
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: Wrong Answer

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


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

    if A[-i-1] > ma:
        ma = A[-i-1]
        maL.append(ma)
    else:
        maL.append(ma)

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

Submission status: Wrong Answer

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()))
    q = deque()
    q.extend(A)

    a0 = A[0]
    B = []
    cnt_a = 1
    max_profit = 0
    while len(q) > 0:
        a = q.popleft()
        if a0 > a:
            a0 = a
            cnt_a = 1
        elif a0 == a:
            cnt_a += 1
        else:
            b0 = a
            cnt_b = 1
            while len(q) > 0:
                b = q.popleft()
                if b0 < b:
                    b0 = b
                    cnt_b = 1
                elif b0 ==b:
                    cnt_b += 1
                else:
                    #B.append((b0 - a0, min(cnt_a, cnt_b)))
                    B.append((b0 - a0, cnt_a))
                    max_profit = max(max_profit, b0 - a0)
                    b0 = -1
                    a0 = b
                    cnt_a = 1

    if b0 != -1:
        #B.append((b0 - a0, min(cnt_a, cnt_b)))
        B.append((b0 - a0, cnt_a))
        max_profit = max(max_profit, b0 - a0)

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

    return cnt


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

Submission status: Wrong Answer

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()))
    q = deque()
    q.extend(A)

    a0 = A[0]
    B = []
    cnt_a = 1
    max_profit = 0
    while len(q) > 0:
        a = q.popleft()
        if a0 > a:
            a0 = a
            cnt_a = 1
        elif a0 == a:
            cnt_a += 1
        else:
            b0 = a
            cnt_b = 1
            while len(q) > 0:
                b = q.popleft()
                if b0 < b:
                    b0 = b
                    cnt_b = 1
                elif b0 ==b:
                    cnt_b += 1
                else:
                    B.append((b0 - a0, min(cnt_a, cnt_b)))
                    max_profit = max(max_profit, b0 - a0)
                    b0 = -1
                    a0 = b
                    cnt_a = 1

    if b0 != -1:
        B.append((b0 - a0, min(cnt_a, cnt_b)))
        max_profit = max(max_profit, b0 - a0)

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

    return cnt


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