Problem: "Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one round counter. The outer circumference of the counter is C meters. Customers cannot go inside the counter.  Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there are N pieces of sushi (vinegared rice with seafood and so on) on the counter. The distance measured clockwise from the point where Nakahashi is standing to the point where the i-th sushi is placed, is x_i meters. Also, the i-th sushi has a nutritive value of v_i kilocalories.  Nakahashi can freely walk around the circumference of the counter. When he reach a point where a sushi is placed, he can eat that sushi and take in its nutrition (naturally, the sushi disappears). However, while walking, he consumes 1 kilocalories per meter.  Whenever he is satisfied, he can leave the restaurant from any place (he does not have to return to the initial place). On balance, at most how much nutrition can he take in before he leaves? That is, what is the maximum possible value of the total nutrition taken in minus the total energy consumed? Assume that there are no other customers, and no new sushi will be added to the counter. Also, since Nakahashi has plenty of nutrition in his body, assume that no matter how much he walks and consumes energy, he never dies from hunger.

Submission attempts (in order):
import numpy as np
import sys
input2 = sys.stdin.read

n, c = map(int, input().split())
AV = np.array(list(map(int, input2().rsplit())), dtype=np.int64)
A, V = AV[::2], AV[1::2]
B = (c - A)[::-1]
XA = np.cumsum(V) - A
XB = np.cumsum(V[::-1]) - B
RSA, RSB = XA - A, XB - B

XRA, XRB = 0, 0
for i in range(n):
    if RSA[i] > 0:
        XRA = max(XRA, RSA[i] + XB[:n - 1 - i].max())
    else:
        break

for i in range(n):
    if RSB[i] > 0:
        XRB = max(XRB, RSB[i] + XA[:n - 1 - i].max())
    else:
        break

print(max(0, max(XA), max(XB), XRA, XRB))


import numpy as np
import sys
input2 = sys.stdin.read

# A: Anti-clockwise, B: Clockwise, V: Values
n, c = map(int, input().split())
AV = np.array(list(map(int, input2().rsplit())), dtype=np.int64)
A, V = AV[::2], AV[1::2]
B = (c - A)[::-1]

XA = np.cumsum(V) - A
XB = np.cumsum(V[::-1]) - B
RSA, RSB = XA - A, XB - B    # Cumulative Values returning to Start

MA, MB = XA.max(), XB.max()
mai, mbi = 0, 0

for i, x in enumerate(XA):
    if x == MA:
        mai = i

for i, x in enumerate(XB):
    if x == MB:
        mbi = i

MRA = max(0, RSA[:n - mbi].max())
MRB = max(0, RSB[:n - mai].max())

print(max(MA + MRB, MB + MRA))


import numpy as np
import sys
input2 = sys.stdin.read

# A: Anti-clockwise, B: Clockwise, V: Values
n, c = map(int, input().split())
AV = np.array(list(map(int, input2().rsplit())), dtype=np.int64)
A, V = AV[::2], AV[1::2]
B = (c - A)[::-1]

XA = np.cumsum(V) - A
XB = np.cumsum(V[::-1]) - B
RXA, RXB = XA - A, XB - B    # Cumulative Values returning to Start

MA = np.zeros(n + 1, dtype=np.int64)
MB = np.zeros(n + 1, dtype=np.int64)
MRA = np.zeros(n + 1, dtype=np.int64)
MRB = np.zeros(n + 1, dtype=np.int64)


def max_mem(lis, mlis):
    for i in range(n):
        mlis[i + 1] = max(mlis[i], lis[i])


max_mem(XA, MA)
max_mem(XB, MB)
max_mem(RXA, MRA)
max_mem(RXB, MRB)

if n == 1:
    print(MA[1])
    exit()



res1, res2 = 0, 0
for i in range(n + 1):
    res1 = max(res1, MA[i] + MRB[n - i])
    res2 = max(res2, MB[i] + MRA[n - i])
    #print(res1, res2)

print(max(res1, res2))


Verdicts: Runtime Error

Wrong Answer

Accepted