Submission #4039369


Source Code Expand

import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,k = li()
a = list(li())

acc_all = [0]
acc_pos = [0]

for ai in a:
    if ai > 0:
        acc_all.append(acc_all[-1] + ai)
        acc_pos.append(acc_pos[-1] + ai)
    else:
        acc_all.append(acc_all[-1] + ai)
        acc_pos.append(acc_pos[-1])

ans = 0    
for st in range(n-k+1):
    black = (acc_all[st+k] - acc_all[st])\
            + (acc_pos[n] - acc_pos[st+k])\
            + (acc_pos[st] - acc_pos[0])
    white = (acc_pos[n] - acc_pos[st+k])\
            + (acc_pos[st] - acc_pos[0])

    ans = max(ans, black, white)
    
print(ans)
    

Submission Info

Submission Time
Task B - Contiguous Repainting
User polarbear08
Language Python (3.4.3)
Score 400
Code Size 1025 Byte
Status AC
Exec Time 204 ms
Memory 17096 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 4
AC × 26
Set Name Test Cases
Sample 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt
All 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt
Case Name Status Exec Time Memory
0_00.txt AC 17 ms 3064 KB
0_01.txt AC 18 ms 3064 KB
0_02.txt AC 17 ms 3064 KB
0_03.txt AC 17 ms 3064 KB
1_00.txt AC 17 ms 3064 KB
1_01.txt AC 17 ms 3064 KB
1_02.txt AC 17 ms 3064 KB
1_03.txt AC 175 ms 5472 KB
1_04.txt AC 203 ms 16996 KB
1_05.txt AC 194 ms 14016 KB
1_06.txt AC 204 ms 16936 KB
1_07.txt AC 203 ms 14640 KB
1_08.txt AC 79 ms 14288 KB
1_09.txt AC 86 ms 16516 KB
1_10.txt AC 88 ms 16056 KB
1_11.txt AC 123 ms 14604 KB
1_12.txt AC 121 ms 14728 KB
1_13.txt AC 121 ms 16012 KB
1_14.txt AC 88 ms 16460 KB
1_15.txt AC 137 ms 14032 KB
1_16.txt AC 160 ms 15760 KB
1_17.txt AC 173 ms 17096 KB
1_18.txt AC 118 ms 14992 KB
1_19.txt AC 100 ms 15984 KB
1_20.txt AC 111 ms 14740 KB
1_21.txt AC 98 ms 15240 KB