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

    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 = []
    while len(q) > 0:
        a = q.popleft()
        if a0 > a:
            a0 = a
        else:
            b0 = a
            while len(q) > 0:
                b = q.popleft()
                if b0 < b:
                    b0 = b
                else:
                    B.append(b0 - a0)
                    b0 = -1
                    a0 = b

    if b0 != -1:
        B.append(b0 - a0)

    max_profit = max(B)
    cnt = 0
    for b in B:
        if b == max_profit:
            cnt += 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 = []
    while len(q) > 0:
        a = q.popleft()
        if a0 >= a:
            a0 = a
        else:
            b0 = a
            while len(q) > 0:
                b = q.popleft()
                if b0 <= b:
                    b0 = b
                else:
                    B.append(b0 - a0)
                    b0 = -1
                    a0 = b

    if b0 != -1:
        B.append(b0 - a0)

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

    return cnt


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

Submission status: Wrong Answer

Solution code:
n,t=map(int,input().split())
a=list(map(int,input().split()))
d=[]
l=10**9+1
for i in range(n-1,0,-1):
    l=min(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: Wrong Answer

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

Submission status: Wrong Answer

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

d = 0
c = 1

m = 0
while m < n - 1:
    y = max(a[m:])
    i = a.index(y)
    if i == m:
        m += 1
        continue
    x = min(a[m:i])
    if y - x == d:
        c += 1
    elif y - x > d:
        d = y - x
        c = 1
    elif y - x < d:
        break
    m = i + 1

print(c)

Submission status: Wrong Answer

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]:
    m[i]=a[i] if i==n-1 else max(m[i+1],a[i])

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

Submission status: Wrong Answer

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(min(c[max(c.keys())],t//2))

Submission status: Wrong Answer

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

Solution code:
N, T = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
buy_price = float('inf')
count = {}
for i in range(1, N):
    buy_price = min(buy_price, A[i])
    profit = A[i] - buy_price
    count[profit] = count.get(profit, 0) + 1
print(count[sorted(count.keys())[-1]])

Submission status: Wrong Answer

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

minA = A[0]
profit = 0
cnt = 0
for i in range(1,N):
    print(i,cnt,profit)
    # A[i] で min(A[0..i-1])を売る場合の利益
    p = A[i]-minA
    if p==profit:
        cnt += 1 
    elif p>profit:
        profit = p
        cnt = 1
    # min(A[0..i]) の更新
    minA = min(minA,A[i])
    
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,t=map(int,input().split())
x=list(map(int,input().split()))
res=[]
t=1
j=False
for i in range(1,n):
    if x[i-1]<x[i]:
        t+=1
        j=True
    elif j:
        res.append(x[i-1]-x[i-t])
        t=1
    else:
        j=False
if j:
    res.append(x[i]-x[i-t+1])
res.sort()
res=res[::-1]
print(res.count(max(res)))

Submission status: Wrong Answer

Solution code:
n,t=map(int,input().split())
x=list(map(int,input().split()))
res=[]
t=1
j=False
for i in range(1,n):
    if x[i-1]<x[i]:
        t+=1
        j=True
    elif j:
        res.append(x[i-1]-x[i-t])
        t=1
    else:
        j=False
if j:
    res.append(x[i]-x[i-t+1])
res.sort()
res=res[::-1]
print(min(t,res.count(max(res))))

Submission status: Wrong Answer

Solution code:

iN,iT = [int(_) for _ in input().split()]
aA = [int(_) for _ in input().split()]
iL = len(aA)

aMaxD = [0]
iMin = aA[0]
iV = 0

def checkMax(aMaxD,iMin,iB):
    iMaxD = 0
    iMaxD = max(iMaxD,iB - iMin)
    if aMaxD[0] < iMaxD:
        aMaxD = [iMaxD]
    elif aMaxD[0] == iMaxD:
        aMaxD.append(iMaxD)
    return aMaxD

for i in range(1,iL-1):
    iB = aA[i-1]
    iN = aA[i]
    if iB - iN > 0:
        if iV >= 0:
            aMaxD = checkMax(aMaxD,iMin,iB)
        iV = -1
    elif iB - iN < 0:
        if iV <= 0:
            iMin = min(iB,iMin)
        iV = 1
aMaxD = checkMax(aMaxD,iMin,aA[-1])
print( len(aMaxD) )

Submission status: Wrong Answer

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

Profit = []
temp = A[0]
for i in range(1, N+1):
    if A[i] < A[i-1]:
        Profit.append(A[i-1]-temp)
        temp = A[i]

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

Submission status: Wrong Answer

Solution code:
N, T = map(int, input().split())
A = [int(x) for x in input().split()]
buy = A[0]
sale = A[0]
benefit = 0
cost = 0
for a in A[1:]:
  if a > sale:
    sale = a
  elif a < buy:
    b = sale - buy
    if b > benefit:
      benefit = b
      cost = 1
    elif b == benefit:
      cost += 1
    buy = a
    sale = a
print(cost)

Submission status: Wrong Answer

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

benefit, min = [], 0
for i in range(len(a)):
    if i == 0 or a[i] <= min:
        min = a[i]
    else:
        benefit.append(a[i]-min)
ans = Counter(benefit)
for _, c in ans.most_common(1):
    print(c)
    exit(0)

Submission status: Wrong Answer

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

benefit, min = [], 0
for i in range(len(a)):
    if i == 0 or a[i] < min:
        min = a[i]
    else:
        b = a[i] - min
        if not b <= 0:
            benefit.append(b)

ans = Counter(benefit)
for _, c in ans.most_common(1):
    print(c)
    exit(0)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from collections import defaultdict

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

B = [x for x in accumulate(A[::-1], max)][::-1]
c = defaultdict(int)
for i in range(1, N):
    c[B[i] - A[i]] += 1
print(c[max(c)])

Submission status: Wrong Answer

Solution code:
NT=input()
NT=NT.rstrip().split(" ")
N=int(NT[0])
T=int(NT[1])

cnt=0
sa=0
min=0
max=0

L=input()
L=L.rstrip().split(" ")
min=int(L[0])
for i in range(1,len(L)):
    if int(L[i])>max:
        max=int(L[i])
    if min>int(L[i]):
        min=int(L[i])
        max=0
    if max-min>sa:
        sa=max-min
        cnt=1
    elif max-min==sa:
        cnt+=1
    #print(cnt,sa,max,min)
print(cnt)

Submission status: Wrong Answer

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

re = 0
max_dif = 0
A_min = A[0]
for i in range(1, N):
    dif = A[i] - min(A_min, A[i-1])
    if max_dif < dif:
        max_dif = dif
        re = 1
    elif dif == max_dif:
        re += 1

print(re)

Submission status: Wrong Answer

Solution code:
N, T = map(int, input().split(" "))
As = list(map(int, input().split(" ")))
max_diff = 0
diffs = []
for i, a in enumerate(As[:-2]):
    flag = True
    for j, b in enumerate(As[i:]):
        diff = b - a
        if diff > 0:
            if diff == max_diff and flag:
                diffs.append(diff)
                flag = False
            elif diff > max_diff:
                max_diff = diff
                diffs = [diff]
                flag = False
print(len(diffs))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n,m=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
b=[]
for i in a:
  if i < m:
    m = i
  else:
    b.append(i-m)
ma=max(b)
c=Counter(b)
print(c[ma])

Submission status: Wrong Answer

Solution code:
N,T = map(int,input().split())
A = list(map(int,input().split()))
bp,sp,prof,pc = 10**9+1,0,0.5,0
for i in range(N-1):
    if A[i] < A[i+1]:
        bp = min(bp,A[i])
        sp = max(sp,A[i+1])
        if prof == sp-bp:
            pc += 1
        elif prof < sp-bp:
            pc = 1
            prof = sp-bp
    elif A[i] > A[i+1]:
        bp,sp = 10**9+1,0
print(pc)

Submission status: Wrong Answer

Solution code:
N,T = map(int,input().split())
A = list(map(int,input().split()))
bp,sp,prof,pc = 10**9+1,0,0.5,0
for i in range(N):
    bp = min(bp,A[i])
    sp = max(sp,A[i])
    if sp-bp > prof:
        prof = sp-bp
        pc = 1
        bp,sp = 10**9+1,0.5
    elif sp-bp == prof:
        pc += 1
        bp,sp = 10**9+1,0.5
print(pc)

Submission status: Wrong Answer

Solution code:
def get_next_int():
    return int(float(input()))


def get_next_ints(delim=" "):
    return tuple([int(float(x)) for x in input().split(delim)])


def get_next_str():
    return input()


def get_next_strs(delim=" "):
    return tuple(input().split(delim))


def get_next_by_types(*value_types, delim=" "):
    return tuple([t(x) for t, x in zip(value_types, input().split(delim))])


def solve():
    N, T = get_next_ints()
    values = get_next_ints()

    r_values = reversed(values)

    count = 0
    max_val = 0
    max_diff = 0
    for value in r_values:
        if value >= max_val:
            max_val = value
            continue
        diff = max_val - value
        if diff > max_diff:
            max_diff = max_val - value
            count = 1
        elif diff == max_diff:
            count += 1
    print(count)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
 
n,t = map(int, raw_input().split())
a = map(int, raw_input().split()) 
 
m = 10*9+1
num = 0
diff = 0
for i in range(n):
    if(a[i]<m):
        m = a[i]
    if(a[i]-m > diff):
        diff = a[i]-m
        num = 1
    elif(a[i]-m == diff):
        num += 1
print(num)

Submission status: Wrong Answer

Solution code:
N, T = list(map(int, input().split()))
ps = list(map(int, input().split()))
min_p = 99999999999999
max_diff = 0
min_n = 0

for i in range(0, N):
    if ps[i] < min_p:
        min_p = ps[i]
    elif max_diff == ps[i] - min_p:
        min_n += 1
    elif max_diff < ps[i] - min_p:
        max_diff = ps[i] - min_p
        min_n = 1

if min_n > T / 2:
    min_n = T / 2

print(str(min_n))

Submission status: Wrong Answer

Solution code:
nt=input().split(" ")
N=int(nt[0])
T=int(nt[1])


a=input().split(" ")
int_a=[]
maxlist=[]
for i in range(N):
    int_a.append(int(a[i]))

reva=int_a
reva.reverse()
max=0
for i in range(N):
    if reva[i]>max:
        max=reva[i]
    maxlist.append(max)

maxlist.reverse()
int_a.reverse()

print(maxlist)
print(int_a)

max=0
count=1
for i in range(N):
    if maxlist[i]-int_a[i]>max:
        count=1
        max=maxlist[i]-int_a[i]
    elif maxlist[i]-int_a[i]==max:
        count+=1

print(count)

Submission status: Wrong Answer

Solution code:
input()
A=list(map(int,input().split()))
d,c,s=0,0,A[0]
for x in A[1:]:
 if x-s<d:
  d,c=x-s,1
 elif x-s==d:
  c+=1
 s=min(s,x)
print(c)

Submission status: Wrong Answer

Solution code:
input()
A=list(map(int,input().split()))
d,c,s=0,0,A[0]
for x in A:
 if x-s<d:
  d,c=x-s,1
 elif x-s==d:
  c+=1
 s=min(s,x)
print(c)

Submission status: Wrong Answer

Solution code:
input()
A=list(map(int,input().split()))
d,c,s=0,0,A[0]
for x in A[1:]:
 if x-s<d:
  d,c=x-s,c
 elif x-s==d:
  c+=1
 s=min(s,x)
print(c)

Submission status: Wrong Answer

Solution code:
input()
A=list(map(int,input().split()))
d,c,s=0,0,A[0]
for x in A:
 if x-s<d:
  d,c=x-s,c
 elif x-s==d:
  c+=1
 s=min(s,x)
print(c)

Submission status: Wrong Answer

Solution code:
def onesawa(a,i):
    if a[i-1]<a[i] and a[i]>=a[i+1]:
        return 1
    elif a[i-1]>=a[i] and a[i]<a[i+1]:
        return 2
    else:
        return 0

N=int(input().split(" ")[0])
put=input().split(" ")
A=[int(put[0])-1]
for i in range(N):
    A.append(int(put[i]))
A.append(A[-1])    

t=0
maxheight=0

k=1
bottom=A[0]
    

while k<=N:
    if onesawa(A,k)==1:
        if maxheight<A[k]-bottom:
            maxheight=A[k]-bottom
            t=1
        elif maxheight==A[k]-bottom:
            t+=1
    elif onesawa(A,k)==2:
        bottom=A[k]
    k+=1    



print(t)

Submission status: Wrong Answer

Solution code:
def onesawa(a,i):
    if a[i-1]<a[i] and a[i]>=a[i+1]:
        return 1
    elif a[i-1]>=a[i] and a[i]<a[i+1]:
        return 2
    else:
        return 0

N=int(input().split(" ")[0])
put=input().split(" ")
A=[]
for i in range(N):
    A.append(int(put[i]))
A.append(A[-1])    

t=1
maxheight=0

k=1
bottom=A[0]
if A[0]>A[1]:
    while onesawa(A,k)!=2:
        k+=1
    bottom=A[k]    

while k<N:
    if onesawa(A,k)==1:
        if maxheight<A[k]-bottom:
            maxheight=A[k]-bottom
            t=1
        elif maxheight==A[k]-bottom:
            t+=1
    elif onesawa(A,k)==2:
        bottom=A[k]
    k+=1    



print(t)

Submission status: Wrong Answer

Solution code:
def onesawa(a,i):
    if a[i-1]<a[i] and a[i]>a[i+1]:
        return 1
    elif a[i-1]>a[i] and a[i]<a[i+1]:
        return 2
    else:
        return 0

N=int(input().split(" ")[0])
put=input().split(" ")
A=[]
for i in range(N):
    A.append(int(put[i]))
A.append(A[-1]-1)    

t=1
maxheight=0

k=0
bottom=A[0]
if A[0]>A[1]:
    k=1
    while onesawa(A,k)!=2:
        k+=1
    bottom=A[k]    

while k<N:
    if onesawa(A,k)==1:
        if maxheight<A[k]-bottom:
            maxheight=A[k]-bottom
            t=1
        elif maxheight==A[k]-bottom:
            t+=1
    elif onesawa(A,k)==2:
        bottom=A[k]
    k+=1    



print(t)

Submission status: Wrong Answer

Solution code:
def onesawa(a,i):
    if a[i-1]<a[i] and a[i]>a[i+1]:
        return 1
    elif a[i-1]>a[i] and a[i]<a[i+1]:
        return 2
    else:
        return 0

N=int(input().split(" ")[0])
put=input().split(" ")
A=[]
for i in range(N):
    A.append(int(put[i]))
A.append(A[-1])    

t=1
maxheight=0

k=0
bottom=A[0]
if A[0]>A[1]:
    k=1
    while onesawa(A,k)!=2:
        k+=1
    bottom=A[k]    

while k<N:
    if onesawa(A,k)==1:
        if maxheight<A[k]-bottom:
            maxheight=A[k]-bottom
            t=1
        elif maxheight==A[k]-bottom:
            t+=1
    elif onesawa(A,k)==2:
        bottom=A[k]
    k+=1    



print(t)

Submission status: Wrong Answer

Solution code:
N,T = [int(x) for x in raw_input().split(" ")]

A = [int(x) for x in raw_input().split(" ")]


mx = -1e10
cnt = 0

for i in range(len(A)-1):
	if max(A[i+1:]) - A[i] > mx:
		mx = max(A[i+1:]) - A[i]
		cnt += 1

	elif max(A[i+1:]) == mx:
		cnt += 1

print cnt

Submission status: Wrong Answer

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

result = 0
diff = 0

for i in range(N - 1):
    if max(A[i+1:]) <= A[i]:
        continue
    elif max(A[i+1:]) - A[i] > diff:
        diff = max(A[i+1:]) - A[i]
        result += 1

print(result)

Submission status: Wrong Answer

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

result = 0
diff = 0
for i in range(N - 1):
    counter = 0
    if max(A[i+1:]) - A[i] < 0:
        continue
    elif max(A[i+1:]) - A[i] > diff:
        diff = max(A[i+1:]) - A[i]
        result += 1
    counter += 1

print(result)

Submission status: Wrong Answer

Solution code:
import sys

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

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

cnt = 0
diff = 0
miniA = -1
while len(A) > 1:
    for i in xrange(1, N):
        if miniA == min(A[i:]):
            continue
        miniA = min(A[i:])
        for j in xrange(i, N):
            if miniA == A[j]:
                maxA = max(A[j:])
                break
        if maxA == miniA:
            A.remove(miniA)
            break;
        if diff == (maxA - miniA):
            cnt += 1
        elif diff < (maxA - miniA):
            diff = (maxA - miniA)
            cnt = 1
        A.remove(maxA)
        A.remove(miniA)
        break;

print cnt

Submission status: Wrong Answer

Solution code:
import sys

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

A = map(int, sys.stdin.readline().split())
peak = 0
cnt_peak = 0
diff = 0
minimum = A[0]
for i in xrange(1, len(A)):
    temp = A[i] - A[i - 1]
    if temp < 0:
        if minimum > A[i]:
            if peak == diff:
                cnt_peak += 1
            elif peak < diff:
                peak = diff
                cnt_peak = 1
            diff = 0
        else:
            diff = A[i] - minimum
    else:
        diff += temp

if peak == diff:
    cnt_peak += 1
elif peak < diff:
    peak = diff
    cnt_peak = 1

print cnt_peak

Submission status: Wrong Answer

Solution code:
import sys
N,T = map(int,sys.stdin.readline().split())

A = map(int,sys.stdin.readline().split())
peak = 0
cnt_peak = 0
diff = 0
for i in xrange(1,len(A)):
    temp = A[i] - A[i-1]
    if temp < 0:
        if peak == diff:
            cnt_peak += 1
        elif peak < diff:
            peak = diff
            cnt_peak = 1
        diff = 0
    else:
        diff += temp

if peak == diff:
    cnt_peak += 1
elif peak < diff:
    peak = diff
    cnt_peak = 1

print cnt_peak

Submission status: Wrong Answer

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

    if n <= 3:
        print(1)
        return

    base = a[-1]
    m = 10 ** 10
    diff_list = []
    for i in range(len(a) - 2, -1, -1):
        if a[i] >= base:
            diff_list.append(base - m)
            base = a[i]
            m = 10 ** 10
        m = min(m, a[i])

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

    base = a[-1]
    m = 10 ** 10
    diff_list = []
    for i in range(len(a) - 2, -1, -1):
        if a[i] >= base:
            diff_list.append(base - m)
            base = a[i]
            m = 10 ** 10
        m = min(m, a[i])

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n, t = (int(i) for i in input().split())
price = [int(i) for i in input().split()]
saved_index = 0
saved_val = 999
def get_min(tr_list,end_indx):
    global saved_index
    global saved_val
    minimum = min(tr_list[saved_index:end_indx+1])
    if saved_val > minimum:
        saved_val = minimum
    saved_index = end_indx
    return saved_val
        
 
profit = [0 for i in range(n-1)]
for i in range(n-1):
    profit[i] = price[i+1] - get_min(price,i+1)
#print("profit",profit)
max_profit = max(profit)
#print("max_profit",max_profit)
result = profit.count(max_profit)
print(result)

Submission status: Wrong Answer

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

count = 1
m = 1000000000
maxrieki = 0

for i in range(n):
    if( m > a[i]):
        m = a[i]
    else:
        if(maxrieki != 0 and maxrieki == a[i]-m):
            count+=1
        elif(maxrieki < (a[i] - m)):
            maxrieki = a[i] - m
            count = 1

print(min(count, int(t/2)))

Submission status: Wrong Answer

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

count = 1
m = 1000000000
maxrieki = 0

for i in range(n):
    m = min(m, a[i])
    if(maxrieki != 0 and maxrieki == a[i]-m):
        count+=1
    if(maxrieki < (a[i] - m)):
        maxrieki = a[i] - m
        count = 1

print(min(count, int(t/2)))

Submission status: Wrong Answer

Solution code:
n, t = (int(i) for i in input().split())
price = [int(i) for i in input().split()]
saved_index = 0
saved_val = 999
def get_min(tr_list,end_indx):
    global saved_index
    global saved_val
    minimum = min(tr_list[saved_index:end_indx])
    if saved_val > minimum:
        saved_val = minimum
    saved_index = end_indx
    return saved_val
        

profit = [0 for i in range(n-1)]
for i in range(n-1):
    profit[i] = price[i+1] - get_min(price,i+1)
#print("profit",profit)
max_profit = max(profit)
#print("max_profit",max_profit)
result = profit.count(max_profit)
print(result)

Submission status: Wrong Answer

Solution code:
import sys
lines = sys.stdin.readlines()
sizes = lines[0].split(" ")
N = int(sizes[0])
T = int(sizes[1])
line = lines[1].split(" ")
inp = []
for i in line:
    inp.append(int(i))

check = []
checkMax = []

#for i in range(len(inp)):
#i=0
#c = []
#for j in range(i+1,len(inp)):
    #if inp[i]<inp[j]:
#    c.append(inp[j]-inp[i])
#check.append(c)
#check=c
#checkMax.append(max(check))

#while (len(check)>1):
#    check.pop(0)
#    checkMax.append(max(check))


#for j in range(1,len(inp)):
#    checkMax[j-1] += inp[0]-inp[j]

count=0
for i in range(1,len(inp)):
    if i==1:
        mi = min(inp[0],inp[1])
        ma = inp[1]-inp[0]
    elif i>1:
        if ma<inp[i]-mi:
            count=1
            ma=inp[i]-mi
        elif ma==inp[i]-mi:
            count+=1
        mi = min(inp[i],mi)

print (count)


#print (check)
#print (checkMax)
#print (checkMax.count(max(checkMax)))

Submission status: Wrong Answer

Solution code:
import sys
lines = sys.stdin.readlines()
sizes = lines[0].split(" ")
N = int(sizes[0])
T = int(sizes[1])
line = lines[1].split(" ")
inp = []
for i in line:
    inp.append(int(i))

check = []
checkMax = []

#for i in range(len(inp)):
#i=0
#c = []
#for j in range(i+1,len(inp)):
    #if inp[i]<inp[j]:
#    c.append(inp[j]-inp[i])
#check.append(c)
#check=c
#checkMax.append(max(check))

#while (len(check)>1):
#    check.pop(0)
#    checkMax.append(max(check))


#for j in range(1,len(inp)):
#    checkMax[j-1] += inp[0]-inp[j]

count=0
for i in range(1,len(inp)):
    if i==1:
        mi = min(inp[0],inp[1])
        ma = max(inp[0],inp[1])-mi
    elif i>1:
        if ma<inp[i]-mi:
            count=1
            ma=inp[i]-mi
        elif ma==inp[i]-mi:
            count+=1
        mi = min(inp[i],mi)

print (count)


#print (check)
#print (checkMax)
#print (checkMax.count(max(checkMax)))

Submission status: Wrong Answer

Solution code:
import numpy as np
N, T = map(int, input().split())
A = np.array(list(map(int, input().split())))
B = A < np.roll(A, 1)
C = A < np.roll(A, -1)
print(np.sum((B * C)[:-1]))

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
   if i == n:
       list.append(int(a[i-1])-int(a[l]))     
       break
   else: 
     while i < n:
        if a[i-1]<a[i]:
           i += 1
        else:
           list.append(max(0,int(a[i-1])-int(a[l])))
           break
     else:
           list.append(max(0,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
   if i == n:
       list.append(int(a[i-1])-int(a[l]))     
       break
   else: 
     while i < n:
        if a[i-1]<a[i]:
           i += 1
        else:
           list.append(max(0,int(a[i-1])-int(a[l])))
           break
     else:
           list.append(max(0,int(a[i-1])-int(a[l])))
           break     
   l += 1

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

Submission status: Wrong Answer

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

diff_val, diff_index = -1, []
cost = 0
mi, ma = A[0], A[0]
lo_indexs, hi_index = 0, 0
for i in range(1, N): # 0
    left = A[0:i]
    right = A[i:N]
    low = min(left)
    hig = max(right)
    temp = hig - low
    if diff_val < temp:
        #print(i)
        diff_val = temp
        lo_indexs, hi_index = left.index(low), right.index(hig)
        cost = min(left.count(low), right.count(hig))
    elif diff_val == temp:
        #print(i)
        if lo_indexs == left.index(low) and hi_index == right.index(hig):
            cost = cost
        else:
            cost += min(left.count(low), right.count(hig))
    
print(cost)

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
   if i == n:
       list.append(int(a[i-1])-int(a[l]))     
       break
   else: 
     while i < n:
        if a[i-1]<a[i]:
           i += 1
        else:
           list.append(max(0,int(a[i])-int(a[l])))
           break
     else:
           list.append(max(0,int(a[i-1])-int(a[l])))
           break     
   l += 1

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

Submission status: Wrong Answer

Solution code:
import numpy as np
N, T = map(int, input().split())
A = np.array(list(map(int, input().split())))
B = A < np.roll(A, 1)
C = A < np.roll(A, -1)
print(np.sum((B * C)[1:-1]))

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
   if i == n:
       list.append(int(a[i-1])-int(a[l]))     
       break
   else: 
     while i < n:
        if a[i-1]<a[i]:
           i += 1
        else:
           list.append(int(a[i-1])-int(a[l]))
           break
     else:
           list.append(int(a[i-1])-int(a[l]))
        
   l += 1

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