Cod sursa(job #2449085)

Utilizator voyagerSachelarie Bogdan voyager Data 18 august 2019 02:03:43
Problema Subsecventa de suma maxima Scor 45
Compilator py Status done
Runda Arhiva educationala Marime 0.72 kb
#!/usr/bin/env python3

import sys

sys.stdout = open('ssm.out', 'w', buffering=1 << 20)

with open('ssm.in', 'r') as fin:
    def nextInt():
        num, s = 0, 1
        while True:
            c = fin.read(1)
            if not c or c == ' ' or c == '\n':
                return num * s
            if c == '-':
                s = -1
            else:
                num = num * 10 + int(c)

    n = nextInt()
    best, crt = [None, None, None], [0, 0, 0]
    for i in range(n):
        x = nextInt()
        if crt[0] < 0:
            crt = [x, i, i]
        else:
            crt[0] += x
            crt[2] = i
        if best[0] is None or crt[0] > best[0]:
            best = crt[:]

    print(best[0], best[1] + 1, best[2] + 1)