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:
dat = raw_input()
(N,T) = dat.split(" ")

N = int(N)
T = int(T)

dat = raw_input()
A = map(int,dat.split(" "))

diffmax = 0
diffno = 0

ma = max(A)

for x in range(0,len(A)-1):
  d = ma - A[x]
  if d > diffmax:
    diffmax = d
    diffno = 1
  elif d == diffmax:
    diffno += 1
  elif d == 0:
    ma = max(A[x+1:])

print diffno

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

mx = max(arr)
print(arr.count(mx))

Submission status: Wrong Answer

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

def main():
    n, t = [int(i) for i in raw_input().split()]
    a_list = [int(i) for i in raw_input().split()]
    num_max_gain = 0
    max_gain = 0
    cur_min_cost = 0
    for i in xrange(1, len(a_list)):
        b_a, a = a_list[i-1], a_list[i]
        if b_a > a:
            cur_min_cost = a
        else:
            if i == 1:
                continue
            gain = a-cur_min_cost
            if gain > max_gain:
                num_max_gain = 1
                max_gain = gain
            elif gain == max_gain:
                num_max_gain += 1
    print num_max_gain

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter


a, b = map(int, raw_input().split())
x = map(int, raw_input().split())
y = [x[i] - x[i-1] for i in range(1, len(x))]
c = Counter(y)
m = 0
for k, v in c.items():
    if k > 0 and m < v:
        m = v
print m

Submission status: Time Limit Exceeded

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

max_num = 0
count = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        if max_num < A[j] - A[i]:
            max_num = A[j] - A[i]
            count = 1
            continue

        if max_num == A[j] - A[i]:
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys 
from collections import deque
from collections import defaultdict
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, T = map(int, readline().split())
A = list(map(int,readline().split()))
B = sorted(A,reverse = True)

d = defaultdict(int)
for i in range(N-1):
    a = A[i]
    p = B[0] - a
    d[p] += 1
    B.remove(a)
d = sorted(d.items(),reverse=True)
print(d[0][1])

Submission status: Time Limit Exceeded

Solution code:
n,t = map(int,input().split())
a = list(map(int,input().split()))
sagaku = [int(0) for i in range(n)]
for i in range(n-1):
    for j in range(i+1,n):
        sagaku[i] = max(sagaku[i],a[j]-a[i])
#print(sagaku)
cnt = 0
mx = max(sagaku)
for i in range(n):
    if mx == sagaku[i]:
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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



max_gain = 0
patrn = 0


for i in range(n):
    for j in range(n-i-1):
        if a[-j-1] - a[i] > max_gain:
            max_gain = a[-j-1] - a[i]
            patrn =1
        elif a[-j-1] - a[i] == max_gain:
            patrn +=1
    
print(patrn)

Submission status: Time Limit Exceeded

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

c = 0
MAX = 0
for i in range(N-1):
    a1 = min(A[:i+1])
    a2 = A[i+1]
    if MAX == a2 - a1:
        c += 1
    elif MAX < a2 - a1:
        MAX = a2 - a1
        c = 1
print(c)

Submission status: Time Limit Exceeded

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

c = 0
MAX = 0
for i in range(N-1):
    for j in range(N-1-i):
        if MAX == A[i+1+j] - A[i]:
            c += 1
        elif MAX < A[i+1+j] - A[i]:
            MAX = A[i+1+j] - A[i]
            c = 1
print(c)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n, t, *a = map(int, open(0).read().split())
    a += [-float("Inf")]
    b = [max(a[i + 1:]) for i in range(n)]
    c = []
    for i in range(n):
        x = a[i]
        y = b[i]
        c.append(y - x)

    d = c.count(max(c))
    print(d)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

li = list(map(int, input().split(" ")))
li_c = []

for i in range(N - 1):
  for j in range(i+1, N):
    li_c.append(li[j] - li[i])

m_num = max(li_c)

print(li_c.count(m_num))

Submission status: Time Limit Exceeded

Solution code:
import sys
import heapq
def v():
    N,T=tuple(map(int,sys.stdin.readline().split()))
    A=list(map(int,sys.stdin.readline().split()))
    d=[]
    for i,a in enumerate(A[:-1]):
        b=max(A[i+1:])
        c=b-a if b>a else 0
        d.append(-c)
    heapq.heapify(d)
    res,x=1,heapq.heappop(d)
    while len(d)>0:
        y=heapq.heappop(d)
        if x==y:res+=1
    print(res)
if __name__=='__main__':v()

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left
from collections import defaultdict

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

inf = 10 ** 9 + 7
dp = [inf] * (N + 1)
ctr = defaultdict(int)
for i in range(N):
    idx = bisect_left(dp, A[i])
    if idx == 0:
        dp = [inf] * (N + 1)
    dp[idx] = A[i]
    ctr[A[i] - dp[0]] += 1

print(min(T, ctr[max(ctr)]))

Submission status: Time Limit Exceeded

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

max_dif=0
max_count=0

for i in range(len(a)-1):
    for j in range(i, len(a)):
    
        dif=a[j]-a[i]
      
        if dif==max_dif:
            max_count+=1
        elif dif>max_dif:
            max_dif=dif
            max_count=1
            
            
print(max_count)

Submission status: Time Limit Exceeded

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

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

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

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

Submission status: Time Limit Exceeded

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

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

revenues = []
for i in range(town):
    max_revenue = 0
    for j in range(i, town):
        if (prices[j]-prices[i] > max_revenue):
            max_revenue = prices[j]-prices[i]
    revenues += [max_revenue]

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

Submission status: Time Limit Exceeded

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

Blist=[0]*N
flag = Alist[1]-Alist[0]
max_a = max(Alist)

for i in range(0,N-1):
    if max_a - Alist[i] >= flag:
        Blist[i] = max(Alist[i+1:])-Alist[i]
        flag = Blist[i]
    else:
        pass
    
wawa = Blist.count(max(Blist))

print(min(wawa,T//2))

Submission status: Time Limit Exceeded

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

Blist=[0]*N
for i in range(0,N-1):
    Blist[i] = max(Alist[i+1:])-Alist[i]
    
wawa = Blist.count(max(Blist))

print(min(wawa,T//2))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N,T = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
ind = 0
rieki = []
if N == 2:
    print(1)
    exit()
while True:
    ma = max(a[ind+1:N])
    kioku = ind+1
    ind = a.index(ma)
    if kioku != ind:
        mi = min(a[kioku:ind])
        rieki.append(ma-mi)
    if ind == N-1:
        break
rieki.sort(reverse = True)
ans = 1
for i in range(len(rieki)-1):
  if rieki[i] == rieki[i+1]:
    ans += 1
  else:
    break
print(ans)

Submission status: Time Limit Exceeded

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

B = []

for i in range(1, N):
  B.append(A[i]-min(A[0:i]))
  
result = B.count(max(B))
print(result)

Submission status: Time Limit Exceeded

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

D = []

for i in range(N-1):
  D.append(int(max(A[i:N+1])-A[i]))

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

print(result)

Submission status: Time Limit Exceeded

Solution code:
n, t = map(int, input().split())
a = list(map(lambda x: int(x), input().split()))
#a = list(map(lambda x: int(x), in1.split()))
w_a = []
str_a = 0

for idx1 in range(len(a) - 1):
    w_a.append(a[idx1])
    if a[idx1 + 1] - min(w_a) > str_a:
        RC = 1
        str_a = a[idx1 + 1] - min(w_a)
    elif a[idx1 + 1] - min(w_a) == str_a:
        RC += 1

print(RC)

Submission status: Time Limit Exceeded

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

n, t = MAP()
a = LIST()
get = 0
ans = 0
b = [a[0]]
for i in range(1, n - 1):
    if a[i - 1] < a[i] < a[i + 1]:
        continue
    b.append(a[i])
b.append(a[-1])
d = [b[i] - min(b[:i]) for i in range(1, len(b))]
mx = max(d)
print(d.count(mx))

Submission status: Time Limit Exceeded

Solution code:
n,t = map(int, input().split())
town = list(map(int, input().split()))
bef_town = [town[0]]
sagaku = 0
count = 0
for i in range(1, n):
    sagaku_next = town[i] - min(bef_town)
    if sagaku_next > sagaku:
        sagaku = sagaku_next
        count = 1
    elif sagaku_next == sagaku:
        count += 1
    bef_town.append(town[i])
print(count)

Submission status: Time Limit Exceeded

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

ans = [max(a[i+1:]) - a[i] for i in range(n-1)]
r = max(ans)
print(ans.count(r))

Submission status: Time Limit Exceeded

Solution code:
N,T=map(int,input().split())
A=tuple(map(int,input().split()))
B={}
for i in range(1,N):
  tmp=A[i]-min(A[:i])
  if tmp not in B:
    B[tmp]=1
  else:
    B[tmp]+=1
maxB=max(B)
print(B[maxB])

Submission status: Time Limit Exceeded

Solution code:
N,T=map(int,input().split())
A=list(map(int,input().split()))
B={}
for i in range(1,N):
  tmp=A[i]-min(A[:i])
  if tmp not in B:
    B[tmp]=1
  else:
    B[tmp]+=1
maxB=max(B)
print(B[maxB])

Submission status: Time Limit Exceeded

Solution code:
import collections
N,T=map(int,input().split())
A=list(map(int,input().split()))
B=[0]*N
for i in range(1,N):
  B[i]=A[i]-min(A[:i])
maxB=max(B)
c=collections.Counter(B)
print(c[maxB])

Submission status: Time Limit Exceeded

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

max_list = []
for i in range(len(A)-1):
    diff = max(A[i:]) - A[i]
    max_list += [diff]*A[i:].count(max(A[i:]))
        
max_num = max_list.count(max(max_list))
        
print(max_num)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

max_list = []
for i in range(len(A)-1):
    diff = A[i:] - A[i]
    max_list += diff.tolist()
        
max_num = 0
for i in max_list:
    if max(max_list) == i:
        max_num += 1
        
print(max_num)

Submission status: Time Limit Exceeded

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

max_list = []
for i in range(len(A)-1):
    for j in range(i+1, len(A)):
        max_list.append(A[j]-A[i])
        
max_num = 0
for i in max_list:
    if max(max_list) == i:
        max_num += 1
        
print(max_num)

Submission status: Time Limit Exceeded

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

saeki = []
maxsaeki = 0
ans = 0
maxringo = max(a)

for i in range(len(a)-1):
    if a[i] == maxringo:
        maxringo = max(a[i+1:])
    s = maxringo - a[i]
    if s == maxsaeki:
        ans += 1
    if s > maxsaeki:
        ans = 1
        maxsaeki = s

print(ans)

Submission status: Time Limit Exceeded

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

saeki = []
maxsaeki = 0
ans = 0

for i in range(len(a)-1):
    hikaku = a[i]
    m = max(a[i+1:])
    s = m - hikaku
    if s == maxsaeki:
        ans += 1
    if s > maxsaeki:
        ans = 1
        maxsaeki = s

print(ans)

Submission status: Time Limit Exceeded

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

saeki = []

for i in range(len(a)-1):
    hikaku = a[i]
    m = max(a[i+1:])
    s = m - hikaku
    if s > 0:
        saeki.append(s)
    else:
        saeki.append(0)

saidaisaeki = max(saeki)
ans = saeki.count(saidaisaeki)
print(ans)

Submission status: Time Limit Exceeded

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


import collections
table=collections.defaultdict(set)
table2=collections.defaultdict(set)
tmp=0
for i in range(N-1):
  for j in range(i+1,N):
    table[A[j]-A[i]].add(i)
    table2[A[j]-A[i]].add(j)
    tmp=max(tmp,A[j]-A[i])
print(min(len(table[tmp]),len(table2[tmp])))

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np

stdin = sys.stdin

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

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

print(answer)

# 40

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np

stdin = sys.stdin

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

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

print(answer)

# 40

Submission status: Time Limit Exceeded

Solution code:
n,t=map(int,input().split())
a=list(map(int,input().split()))
lmin=[a[0]]
rmax=[a[-1]]
for i in range(1,n):
  if a[i]<=lmin[-1]:
    lmin.append(a[i])
  else:
    lmin.append(lmin[-1])
  if a[-i-1]>=rmax[-1]:
    rmax.append(a[-i-1])
  else:
    rmax.append(rmax[-1])
mxls=[rmax[-i-2]-lmin[i] for i in range(n-1)]
mxls.append(-10**18)
ans=0
for i in range(n-1):
  if mxls[i]==max(mxls) and mxls[i]!=mxls[i+1]:
    ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,t = map(int,input().split())
a = list(map(int,input().split()))
ans = [0]*n
for i in range(n):
    flag = min(a[:i+1])
    ans[i] = a[i]-flag
print(ans.count(max(ans)))

Submission status: Time Limit Exceeded

Solution code:
n,t = map(int,input().split())
a = list(map(int,input().split()))
ans = [0]*n
flag = max(a)
flag_2 = a.index(flag)
for i in range(n):
  if i <= flag_2:
    ans[i] = flag-a[i]
  else:
    flag = max(a[i:n])
    flag_2 = a.index(flag)
    ans[i] = flag-a[i]
print(ans.count(max(ans)))

Submission status: Time Limit Exceeded

Solution code:
import array
n,t = map(int,input().split())
a = list(map(int,input().split()))
a = array.array("i",a)
ans = []
flag = max(a)
flag_2 = a.index(flag)
for i in range(n):
  if i <= flag_2:
    ans.append(flag-a[i])
  else:
    flag = max(a[i:n])
    flag_2 = a.index(flag)
    ans.append(flag-a[i])
print(ans.count(max(ans)))

Submission status: Time Limit Exceeded

Solution code:
n,t = map(int,input().split())
a = list(map(int,input().split()))
ans = []
flag = max(a)
flag_2 = a.index(flag)
for i in range(n):
  if i <= flag_2:
    ans.append(flag-a[i])
  else:
    flag = max(a[i:n])
    flag_2 = a.index(flag)
    ans.append(flag-a[i])
print(ans.count(max(ans)))

Submission status: Time Limit Exceeded

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

c=0
dif=0
for i in range(1,n):
    m=min(a[:i])
    if(dif<a[i]-m):
        c=1
        dif=a[i]-m
    elif(dif==a[i]-m):
        c+=1
print(c)

Submission status: Time Limit Exceeded

Solution code:
#import math.sqrt as sqrt
#data = list(map(int,input().split()))

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

max = a[1]-a[0]
count = 0



for i in range(N-1):
    for j in range(i, N):
      if a[j]-a[i] > max:
          max = a[j]-a[i]
          count = 1
      elif a[j]-a[i] == max:
          count += 1

print(count)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N,T = map(int,input().split())
A=np.array(input().split(),dtype=np.int32)
s=[]
count=0
for i in range(1,N):
  s += [A[i]-min(A[0:i])]
for j in range(len(s)):
  if s[j]==max(s):
    count +=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N,T = map(int,input().split())
A=[int(x) for x in input().split()]
s=[]
count=0
for i in range(1,N):
  s += [A[i]-min(A[0:i])]
for j in range(len(s)):
  if s[j]==max(s):
    count +=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
def solve():
    N, T = tuple(map(int, input().split()))
    AS = tuple(map(int, input().split()))

    # print(N, T)
    # print(AS)

    m = -float('inf')
    c = 0
    for i in range(len(AS)):
        for x in range(i + 1, len(AS)):
            # max が見つかったら max を更新し, counter を 1 にリセット
            d = AS[x] - AS[i]
            if m < d:
                m = d
                c = 1
            elif m == d: # max と同じ値なら counter を ++
                c += 1
    
    return c


if __name__ == '__main__':
    res = solve()
    print(res)

Submission status: Time Limit Exceeded

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: Time Limit Exceeded

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):
        count+=1
    elif(A[ind+1]-min(lst) >= rieki):
        rieki=A[ind+1]-min(lst)
        count=1


print(count)

Submission status: Time Limit Exceeded

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


rieki=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=0
for ind,i in enumerate(A):
    lst=A[:ind+1]
    if(ind==len(A)-1):
        break
    elif(A[ind+1]-min(lst) == rieki):
        count+=1
print(count)

Submission status: Time Limit Exceeded

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 = maxvalue - minvalue
count = 1
flag = 0
j = 0
for i in range(n-1):
  if minvalue > L[i]:
    minvalue = L[i]
    flag = 1
    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: Time Limit Exceeded

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: Time Limit Exceeded

Solution code:
import copy
 
#  print("L[i]:{0}, min:{1}, max:{2}, subt:{3}, count:{4}".format(L[i], minvalue, maxvalue, subt, count))
 
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
for i in range(n-1):
  if minvalue > L[i]:
    minvalue = L[i]
    flag = 1
  LL = LL[1:]
  if maxvalue == L[i]:
    maxvalue = max(LL)
 
  tsubt = maxvalue - minvalue
  if tsubt > subt:
    subt = tsubt
    count = 1
  elif tsubt == subt and flag == 1:
    count += 1
  flag = 0
 
print(count)

Submission status: Time Limit Exceeded

Solution code:
import copy

#  print("L[i]:{0}, min:{1}, max:{2}, subt:{3}, count:{4}".format(L[i], minvalue, maxvalue, subt, count))

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
for i in range(n-1):
  if minvalue > L[i]:
    minvalue = L[i]
    flag = 1
  LL.remove(L[i])
  if maxvalue == L[i]:
    maxvalue = max(LL)

  tsubt = maxvalue - minvalue
  if tsubt > subt:
    subt = tsubt
    count = 1
  elif tsubt == subt and flag == 1:
    count += 1
  flag = 0
 
print(count)

Submission status: Time Limit Exceeded

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

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(maxvalue)
    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: Time Limit Exceeded

Solution code:
import copy
 
n, t = map(int, input().split())
L = [int(i) for i in input().split()]
LL = copy.deepcopy(L)
LL.sort()
 
minvalue = L[0]
maxvalue = max(LL)
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: Time Limit Exceeded

Solution code:
import copy
import numpy as np
 
n, t = map(int, input().split())
L = np.array([int(i) for i in input().split()])
#LL = L.copy()
#LL = np.sort(LL)

minvalue = L[0]
maxvalue = L[0]
subt = 0
count = 1
flag = 0
for i in range(n-1):
  i = 0
  if minvalue > L[i]:
    minvalue = L[i]
    flag = 1

  maxvalue = max(L)
  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))
  L = L[1:]   
print(count)

Submission status: Time Limit Exceeded

Solution code:
import copy

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

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: Time Limit Exceeded

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
for i in range(n-1):
  if minvalue > L[i]:
    minvalue = L[i]
    flag = 1
  if maxvalue == L[i]:
    LL.remove(maxvalue)
    maxvalue = max(LL)
  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)