List1 - 구간합

광어회깍뚝썰기·2021년 7월 22일
0

swea-intermediate

목록 보기
4/51
for tc in range(1,int(input())+1):
    N,M = map(int,input().split())
    arr = list(map(int,input().split()))
    
    ans=[]
    for i in range(N-M+1):
        cal = sum(arr[i:i+M])
        ans.append(cal)  
    res=max(ans)-min(ans)
    
    print(f'#{tc} {res}')

극단적인 경우(ex:N과 M이 같을 때)부터 고려하면 지정 범위에 대한 검토을 더 쉽게 할 수 있다.

0개의 댓글

관련 채용 정보