Created
September 30, 2017 17:12
-
-
Save magicleon94/67e80f926e84b1ed965292866a3f5af8 to your computer and use it in GitHub Desktop.
For Hackerrank competition: https://www.hackerrank.com/rest/contests/university-codesprint-3/challenges/erupting-volcanoes/download_pdf?language=English
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/python | |
import sys | |
if __name__ == "__main__": | |
n = int(raw_input().strip()) | |
m = int(raw_input().strip()) | |
grid = [[0 for k in range(n)] for i in range(n)] | |
for a0 in xrange(m): | |
x, y, w = raw_input().strip().split(' ') | |
x, y, w = [int(x), int(y), int(w)] | |
grid[x][y] += w | |
for d in range(1,w): | |
for kx in [-d,d]: | |
for ky in range(-d,d+1): | |
newX = x+kx | |
newY = y+ky | |
if newX>=0 and newX<n and newY>=0 and newY<n: | |
grid[newX][newY] += w-d | |
for ky in [-d,d]: | |
for kx in range(-d+1,d): | |
newX = x+kx | |
newY = y+ky | |
if newX>=0 and newX<n and newY>=0 and newY<n: | |
grid[newX][newY] += w-d | |
print max([max(x) for x in grid]) | |
#for x in grid: | |
#print x | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment