Submission #3007719


Source Code Expand

from itertools import accumulate

N, C = map(int, input().split())
sushi = [[int(x) for x in input().split()] for _ in range(N)]


def solve():
    """
    O(N)
    Bを固定したときの最適なAを事前に計算
    """
    V = [0] * (N + 1)
    for i in range(N):
        V[i + 1] = V[i] + sushi[i][1]

    f1 = [0] + [V[a + 1] - sushi[a][0] for a in range(N)]
    f2 = [0] + [V[a + 1] - 2 * sushi[a][0] for a in range(N)]

    g1 = [x for x in accumulate(f1, max)]
    g2 = [x for x in accumulate(f2, max)]

    ans = 0
    for j in range(N + 1):
        # OA
        if j == 0:
            i = N
        else:
            i = j - 1

        # OB
        if j == 0:
            ob_x = 0
        else:
            ob_x = C - sushi[j - 1][0]
        ob_v = V[N] - V[j - 1]

        # 2OA + OB
        ans = max(ans, g2[i] + ob_v - ob_x)

        # OA + 2OB
        ans = max(ans, g1[i] + ob_v - 2 * ob_x)
    print(ans)


solve()

Submission Info

Submission Time
Task D - Static Sushi
User xkumiyu
Language Python (3.4.3)
Score 500
Code Size 980 Byte
Status AC
Exec Time 514 ms
Memory 35464 KB

Judge Result

Set Name Sample Subtask1 Subtask2
Score / Max Score 0 / 0 300 / 300 200 / 200
Status
AC × 4
AC × 29
AC × 50
Set Name Test Cases
Sample a01, a02, a03, a04
Subtask1 a01, a02, a03, a04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29
Subtask2 a01, a02, a03, a04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29, c30, c31, c32, c33, c34, c35, c36, c37, c38, c39, c40, c41, c42, c43, c44, c45, c46, c47, c48, c49, c50
Case Name Status Exec Time Memory
a01 AC 18 ms 3064 KB
a02 AC 18 ms 3064 KB
a03 AC 18 ms 3064 KB
a04 AC 18 ms 3064 KB
b05 AC 18 ms 3064 KB
b06 AC 18 ms 3064 KB
b07 AC 18 ms 3064 KB
b08 AC 18 ms 3064 KB
b09 AC 18 ms 3064 KB
b10 AC 18 ms 3064 KB
b11 AC 18 ms 3064 KB
b12 AC 18 ms 3064 KB
b13 AC 18 ms 3064 KB
b14 AC 18 ms 3064 KB
b15 AC 18 ms 3064 KB
b16 AC 18 ms 3064 KB
b17 AC 18 ms 3064 KB
b18 AC 18 ms 3064 KB
b19 AC 18 ms 3064 KB
b20 AC 18 ms 3064 KB
b21 AC 18 ms 3064 KB
b22 AC 18 ms 3064 KB
b23 AC 18 ms 3064 KB
b24 AC 18 ms 3064 KB
b25 AC 18 ms 3064 KB
b26 AC 18 ms 3064 KB
b27 AC 18 ms 3064 KB
b28 AC 18 ms 3064 KB
b29 AC 18 ms 3064 KB
c30 AC 460 ms 28900 KB
c31 AC 497 ms 35444 KB
c32 AC 495 ms 35464 KB
c33 AC 499 ms 35400 KB
c34 AC 483 ms 35380 KB
c35 AC 461 ms 28900 KB
c36 AC 495 ms 32184 KB
c37 AC 499 ms 35360 KB
c38 AC 498 ms 35360 KB
c39 AC 510 ms 35384 KB
c40 AC 502 ms 35384 KB
c41 AC 492 ms 35380 KB
c42 AC 501 ms 35360 KB
c43 AC 66 ms 6388 KB
c44 AC 508 ms 35464 KB
c45 AC 23 ms 3316 KB
c46 AC 508 ms 35360 KB
c47 AC 18 ms 3064 KB
c48 AC 514 ms 35464 KB
c49 AC 507 ms 35464 KB
c50 AC 500 ms 35380 KB