Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.028 s | 3 KBi |
#2 |
Correcto
|
0.03 s | 3 KBi |
#3 |
Correcto
|
0.043 s | 4 KBi |
#4 |
Correcto
|
0.033 s | 3 KBi |
#5 |
Correcto
|
0.034 s | 3 KBi |
#6 |
Correcto
|
0.024 s | 3 KBi |
#7 |
Correcto
|
0.032 s | 3 KBi |
#8 |
Correcto
|
0.035 s | 3 KBi |
#9 |
Correcto
|
0.032 s | 3 KBi |
#10 |
Correcto
|
0.03 s | 3 KBi |
#11 |
Correcto
|
0.027 s | 3 KBi |
#12 |
Correcto
|
0.035 s | 3 KBi |
#13 |
Correcto
|
0.03 s | 3 KBi |
#14 |
Correcto
|
0.042 s | 5 KBi |
#15 |
Correcto
|
0.041 s | 3 KBi |
#16 |
Correcto
|
0.036 s | 7 KBi |
#17 |
Correcto
|
0.782 s | 12 KBi |
#18 |
Correcto
|
0.658 s | 11 KBi |
#19 |
Correcto
|
0.637 s | 12 KBi |
#20 |
Correcto
|
0.651 s | 12 KBi |
#21 |
Correcto
|
0.621 s | 11 KBi |
#22 |
Correcto
|
0.872 s | 11 KBi |
#23 |
Correcto
|
0.77 s | 11 KBi |
#24 |
Correcto
|
0.914 s | 11 KBi |
"""Divide and conquer""" def find_best(a): n = len(a) # Caso base if n == 1: return a[0] half = n // 2 left = a[0:half] # cuando n es impar tiene un elemento menos que right 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_rigth = a[half] for i in range(half + 1, n): sum_rigth += a[i] best_sum_right = max(best_sum_right, sum_rigth) # 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) return 0 n = int(input()) a = [int(x) for x in input().split()] print(find_best(a))