본문 바로가기

알고리즘

[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)))

 

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