본문 바로가기

알고리즘

[SWEA] 구간 합 (Python)

T = int(input())

for test_case in range(1, T + 1):
    n, m = map(int, input().split())
    number = list(map(int, input().split()))
    sums = []
    for i in range(n-m+1):
        sums.append(sum(number[i:i+m]))
    print('#{} {}'.format(test_case, max(sums) - min(sums)))

 

'알고리즘' 카테고리의 다른 글

[SWEA] 전기버스 (Python)  (0) 2020.10.21
[SWEA] 숫자 카드 (Python)  (0) 2020.10.21
[SWEA] 5658. 보물상자 비밀번호 (Python)  (0) 2020.10.21
[SWEA] 종이 붙이기 (Python)  (0) 2020.10.21
[SWEA] 괄호 검사 (Python)  (0) 2020.10.21