Submission #4032126


Source Code Expand

n,c=map(int, input().split())
a=[[0,0]]+[list(map(int, input().split())) for i in range(n)]+[[c,0]]
m=[0]
h=[0]
mb=[0]
hb=[0]
for i in range(n+1):
    m.append(m[-1]-a[i+1][0]+a[i][0]+a[i+1][1])
    mb.append(m[-2]-a[i+1][0]+a[i][0]+a[i+1][1]-a[i+1][0])
    h.append(h[-1]-a[-i-1][0]+a[-i-2][0]+a[-i-2][1])
    hb.append(h[-2]-a[-i-1][0]+a[-i-2][0]+a[-i-2][1]-c+a[-i-2][0])

mm=[0]
for i in range(n):
    mm.append(max(mm[-1],m[i+1]))
hm=[0]
for i in range(n):
    hm.append(max(hm[-1],h[i+1]))
    
ans=max(hm[-1],mm[-1])
for i in range(1,n):
    ans=max(hb[i]+mm[-i-1], mb[i]+hm[-i-1],ans)
print(ans)

Submission Info

Submission Time
Task D - Static Sushi
User chun1182
Language Python (3.4.3)
Score 500
Code Size 624 Byte
Status AC
Exec Time 794 ms
Memory 48808 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 19 ms 3064 KB
b10 AC 18 ms 3064 KB
b11 AC 19 ms 3064 KB
b12 AC 18 ms 3064 KB
b13 AC 18 ms 3064 KB
b14 AC 19 ms 3064 KB
b15 AC 19 ms 3064 KB
b16 AC 19 ms 3064 KB
b17 AC 19 ms 3064 KB
b18 AC 18 ms 3064 KB
b19 AC 19 ms 3064 KB
b20 AC 19 ms 3064 KB
b21 AC 19 ms 3064 KB
b22 AC 18 ms 3064 KB
b23 AC 18 ms 3064 KB
b24 AC 18 ms 3064 KB
b25 AC 19 ms 3064 KB
b26 AC 18 ms 3064 KB
b27 AC 18 ms 3064 KB
b28 AC 20 ms 3064 KB
b29 AC 19 ms 3064 KB
c30 AC 675 ms 36748 KB
c31 AC 711 ms 46808 KB
c32 AC 750 ms 47232 KB
c33 AC 723 ms 47468 KB
c34 AC 708 ms 47708 KB
c35 AC 691 ms 36748 KB
c36 AC 689 ms 39192 KB
c37 AC 699 ms 47308 KB
c38 AC 717 ms 46708 KB
c39 AC 757 ms 48188 KB
c40 AC 717 ms 48808 KB
c41 AC 707 ms 46560 KB
c42 AC 732 ms 48540 KB
c43 AC 84 ms 7436 KB
c44 AC 765 ms 47200 KB
c45 AC 25 ms 3444 KB
c46 AC 718 ms 47776 KB
c47 AC 19 ms 3064 KB
c48 AC 712 ms 48480 KB
c49 AC 704 ms 47128 KB
c50 AC 794 ms 47116 KB