Skip to content

Instantly share code, notes, and snippets.

@KoStard
Last active March 20, 2018 05:51
Show Gist options
  • Save KoStard/8fd1648ff5deb4b61985a6d4f2613fa8 to your computer and use it in GitHub Desktop.
Save KoStard/8fd1648ff5deb4b61985a6d4f2613fa8 to your computer and use it in GitHub Desktop.
squares = []
mx = 0
class Square:
def __init__(self, height, val = 0):
if val == 0:
self.val = height
else:
self.val = val
self.height = height
def cont(self):
self.val+=self.height
def duplicate_and_decr(self, new_h):
global mx
if self.val > mx:
mx = self.val
squares[squares.index(self)] = Square(new_h, self.val - (self.val/self.height)*(self.height-new_h)+new_h)
del self
def end(self):
global mx
if self.val > mx:
mx = self.val
del self
def get_massive(massive):
global squares, mx
for i in range(len(massive)):
if i==0:
squares.append(Square(massive[i]))
else:
if massive[i]>massive[i-1]:
for s in squares:
s.cont()
squares.append(Square(massive[i]))
elif massive[i]<massive[i-1]:
for s in squares:
if s.height>massive[i]:
s.duplicate_and_decr(massive[i])
else:
s.cont()
else:
for s in squares:
s.cont()
for s in squares:
s.end()
print(mx)
"""
Для тестирования
if __name__ == "__main__":
get_massive(
[2, 1, 4, 5, 1, 3, 3]
)
### Тесты
# [1,2,3,4,5,6,7] -> 16
# [7,6,5,4,3,2,1] -> 16
# [1,2,3,4,3,2,1] -> 10
# [100,1,51,51] -> 102
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment