Submission #1072583


Source Code Expand

Copy
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
a = 0
for i in range(N):
	if A[i] > 0:
		a += A[i]
p = sum([i for i in A[:K] if i > 0])
m = sum([i for i in A[:K] if i < 0])
ans = max(a+m,a-p)
for i in range(N-K):
	p = p - max(0,A[i]) + max(0,A[i+K])
	m = m - min(0,A[i]) + min(0,A[i+K])
	ans = max(ans, a-p, a+m)
print(ans)

Submission Info

Submission Time
Task B - Contiguous Repainting
User TAB
Language Python3 (3.4.3)
Score 400
Code Size 359 Byte
Status
Exec Time 228 ms
Memory 14608 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt
All 400 / 400 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 23 ms 3064 KB
0_01.txt 23 ms 3064 KB
0_02.txt 22 ms 3064 KB
0_03.txt 22 ms 3064 KB
1_00.txt 22 ms 3064 KB
1_01.txt 22 ms 3064 KB
1_02.txt 22 ms 3064 KB
1_03.txt 198 ms 5024 KB
1_04.txt 228 ms 14528 KB
1_05.txt 217 ms 14500 KB
1_06.txt 227 ms 14052 KB
1_07.txt 223 ms 14040 KB
1_08.txt 81 ms 13912 KB
1_09.txt 86 ms 14220 KB
1_10.txt 89 ms 14304 KB
1_11.txt 129 ms 14256 KB
1_12.txt 125 ms 13948 KB
1_13.txt 135 ms 14136 KB
1_14.txt 94 ms 13952 KB
1_15.txt 147 ms 14608 KB
1_16.txt 173 ms 14000 KB
1_17.txt 189 ms 14096 KB
1_18.txt 129 ms 14576 KB
1_19.txt 115 ms 14012 KB
1_20.txt 124 ms 13880 KB
1_21.txt 107 ms 14512 KB