[SWEA D2] 2001. 파리 퇴치

shin·2022년 11월 14일
0

CodingTest 문제 풀이

목록 보기
33/79
post-thumbnail

풀이

T = int(input())
for t in range(1, T+1):
    N, M = map(int, input().split(" "))
    arr = [list(map(int, input().split(" "))) for _ in range(N)]
    result = 0
    for i in range(0, N - M + 1):
        for j in range(0, N - M + 1):
            total = 0
            arr2 = []
            for k in range(M):
                arr2 += arr[i + k][j:j + M]
            for a in arr2:
                total += a
            if total > result:
                result = total
    print(f"#{t} {result}")
  • array slice를 활용
profile
Backend development

0개의 댓글