https://www.codetree.ai/missions/8/problems/sum-of-n-integers-3/introduction
n, k = map(int, input().split(" "))
graph = []
prefix = [[0 for _ in range(n+1)] for _ in range(n+1)]
graph.append([0 for _ in range(n+1)])
for _ in range(n):
temp = [0] + list(map(int, input().rstrip().split(" ")))
graph.append(temp)
for i in range(1, n+1):
for j in range(1, n+1):
prefix[i][j] = prefix[i][j-1] + prefix[i-1][j] - prefix[i-1][j-1] + graph[i][j]
max_val = 0
for i in range(k, n+1):
for j in range(k, n+1):
# print(i, j)
max_val = max(max_val, prefix[i][j] - prefix[i-k][j] - prefix[i][j-k] + prefix[i-k][j-k])
print(max_val)
728x90
반응형
'🔻PS > Codetree' 카테고리의 다른 글
[Codetree] 예술성 Python (1) | 2024.10.15 |
---|---|
[Codetree] 트로미노 Python (0) | 2024.10.01 |
[Codetree] 정수 n개의 합 2 Python (0) | 2024.09.19 |
[Codetree] 수들 중 최솟값 최대화하기 Python (0) | 2024.09.12 |
[Codetree] 외판원 순회 Python (0) | 2024.09.12 |