Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.03 s | 3 KBi |
#2 |
Correcto
|
0.028 s | 3 KBi |
#3 |
Correcto
|
0.031 s | 7 KBi |
#4 |
Correcto
|
0.033 s | 3 KBi |
#5 |
Correcto
|
0.031 s | 3 KBi |
#6 |
Correcto
|
0.031 s | 3 KBi |
#7 |
Correcto
|
0.032 s | 3 KBi |
#8 |
Correcto
|
0.03 s | 3 KBi |
#9 |
Correcto
|
0.025 s | 3 KBi |
#10 |
Correcto
|
0.027 s | 3 KBi |
#11 |
Correcto
|
0.033 s | 3 KBi |
#12 |
Correcto
|
0.032 s | 3 KBi |
#13 |
Correcto
|
0.031 s | 3 KBi |
#14 |
Correcto
|
0.025 s | 3 KBi |
#15 |
Correcto
|
0.03 s | 3 KBi |
#16 |
Correcto
|
0.051 s | 6 KBi |
#17 |
Correcto
|
0.755 s | 11 KBi |
#18 |
Correcto
|
0.794 s | 12 KBi |
#19 |
Correcto
|
0.814 s | 12 KBi |
#20 |
Correcto
|
0.549 s | 12 KBi |
#21 |
Correcto
|
0.915 s | 11 KBi |
#22 |
Correcto
|
0.723 s | 11 KBi |
#23 |
Correcto
|
0.796 s | 11 KBi |
#24 |
Correcto
|
0.762 s | 11 KBi |
def find_best(a): n = len(a) # Caso base if n == 1: return a[0] half = n // 2 left = a[0:half] right = a[half:] # Caso recursivo ("Divide") best = max(find_best(left), find_best(right)) # "Conquer" best_sum_left = a[half - 1] sum_left = a[half - 1] for i in range(half - 2, -1, -1): sum_left += a[i] best_sum_left = max(best_sum_left, sum_left) best_sum_right = a[half] sum_right = a[half] for i in range(half+1, n): sum_right += a[i] best_sum_right = max(best_sum_right, sum_right) # La suma del mejor subarreglo que cruza la linea roja es best_sum_left + best_sum_right return max(best, best_sum_left + best_sum_right) n = int(input()) a = [int(x) for x in input().split()] print(find_best(a))