adc soluções em python
This commit is contained in:
24
maximum-subarray-sum/src/saad.py
Normal file
24
maximum-subarray-sum/src/saad.py
Normal file
@@ -0,0 +1,24 @@
|
||||
class solver:
|
||||
def __init__(self):
|
||||
self.v_ = []
|
||||
self.n = 0
|
||||
|
||||
def read_input(self):
|
||||
self.n = int(input())
|
||||
self.v_ = list(map(int, input().split()))
|
||||
|
||||
def solve(self):
|
||||
(v, n) = self.v_, self.n
|
||||
dp = [ x for x in v]
|
||||
for i in range(1, n):
|
||||
dp[i] = max(dp[i-1] + v[i], dp[i])
|
||||
ans = max(dp)
|
||||
print(ans)
|
||||
|
||||
def main()->None:
|
||||
s = solver()
|
||||
s.read_input()
|
||||
s.solve()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user