AcWing 99. 【Python】激光炸弹
原题链接
简单
作者:
tt2767
,
2019-12-14 00:42:37
,
所有人可见
,
阅读 899
import sys
import re
def read(raw):
sbuffer = list()
for s in raw:
if re.match('\s', s) is None:
sbuffer.append(s)
elif len(sbuffer) > 0:
yield ''.join(sbuffer)
sbuffer = list()
yield ''.join(sbuffer)
pin = read(sys.stdin.read())
n = int(pin.next())
r = int(pin.next())
col = r
row = r
graph = [[0]*5002 for _ in range(5002)]
for _ in range(n):
x = int(pin.next()) + 1
y = int(pin.next()) + 1
w = int(pin.next())
graph[x][y] += w
col = max(col, y)
row = max(row, x)
for i in range(1, row+1):
for j in range(1, col+1):
graph[i][j] += graph[i][j-1] + graph[i-1][j] - graph[i-1][j-1]
res = 0
for i in range(r, row+1):
for j in range(r, col+1):
ans = graph[i][j] - graph[i-r][j] - graph[i][j-r] + graph[i-r][j-r]
res = max(ans, res)
print res