#globals
#Number of commercial breaks. #Price of Commercial Break
N,P = map(int, input().split())

#memoization
result = [0]*N

#STUDENT lISTENERS
Students =  list(map(lambda N: int(N) - P, input().split()))

def computeMaxSubArray(index):
    if index == 0:
        result[index] = Students[0]
        return result[index]
    else:
        result[index] = Students[index] + max(0, computeMaxSubArray(index-1))
        return result[index] 
     
def main():
    for i in range(len(Students)):
        computeMaxSubArray(i)  
    print(max(result))


if __name__ == "__main__":
    main()

cec0b2429205de0bec5819ac3be2565f4fa6d18e
<mask token>

<mask token>


def main():
    for i in range(len(Students)):
        computeMaxSubArray(i)
    print(max(result))


<mask token>

<mask token>


def computeMaxSubArray(index):
    if index == 0:
        result[index] = Students[0]
        return result[index]
    else:
        result[index] = Students[index] + max(0, computeMaxSubArray(index - 1))
        return result[index]


def main():
    for i in range(len(Students)):
        computeMaxSubArray(i)
    print(max(result))


if __name__ == '__main__':
    main()

N, P = map(int, input().split())
result = [0] * N
Students = list(map(lambda N: int(N) - P, input().split()))


def computeMaxSubArray(index):
    if index == 0:
        result[index] = Students[0]
        return result[index]
    else:
        result[index] = Students[index] + max(0, computeMaxSubArray(index - 1))
        return result[index]


def main():
    for i in range(len(Students)):
        computeMaxSubArray(i)
    print(max(result))


if __name__ == '__main__':
    main()

#globals
#Number of commercial breaks. #Price of Commercial Break
N,P = map(int, input().split())

#memoization
result = [0]*N

#STUDENT lISTENERS
Students =  list(map(lambda N: int(N) - P, input().split()))

def computeMaxSubArray(index):
    if index == 0:
        result[index] = Students[0]
        return result[index]
    else:
        result[index] = Students[index] + max(0, computeMaxSubArray(index-1))
        return result[index] 
     
def main():
    for i in range(len(Students)):
        computeMaxSubArray(i)  
    print(max(result))


if __name__ == "__main__":
    main()
