█████████ ████ ███░░░░░███ ░░███ ███ ░░░ ██████ ███████ ██████ ██████ ░███ ███░░███ ███░░███ ███░░███ ███░░███ ░███ ░███ ░███░███ ░███ ░███████ ░███ ░███ ░░███ ███░███ ░███░███ ░███ ░███░░░ ░███ ░███ ░░█████████ ░░██████ ░░████████░░██████ ░░██████ ░░░░░░░░░ ░░░░░░ ░░░░░░░░ ░░░░░░ ░░░░░░

Envío 2153

Problema 0x94 - Subarreglo de máxima suma

  • Autor: Javier
  • Fecha: 2020-11-27 01:48:25 UTC (Hace más de 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.007 s 1 KBi
#2
Correcto
0.008 s 1 KBi
#3
Correcto
0.006 s 1 KBi
#4
Correcto
0.006 s 1 KBi
#5
Correcto
0.007 s 1 KBi
#6
Correcto
0.005 s 1 KBi
#7
Correcto
0.006 s 1 KBi
#8
Correcto
0.006 s 1 KBi
#9
Correcto
0.007 s 1 KBi
#10
Correcto
0.008 s 1 KBi
#11
Correcto
0.006 s 1 KBi
#12
Correcto
0.006 s 1 KBi
#13
Correcto
0.007 s 1 KBi
#14
Correcto
0.007 s 1 KBi
#15
Correcto
0.014 s 1 KBi
#16
Correcto
0.015 s 1 KBi
#17
Tiempo límite excedido
0.894 s 2 KBi
#18
Tiempo límite excedido
0.793 s 2 KBi
#19
Tiempo límite excedido
1.029 s 2 KBi
#20
Tiempo límite excedido
1.043 s 2 KBi
#21
Tiempo límite excedido
0.759 s 2 KBi
#22
Tiempo límite excedido
0.964 s 2 KBi
#23
Tiempo límite excedido
0.861 s 2 KBi
#24
Tiempo límite excedido
0.856 s 2 KBi
Puntos totales: 67 / 100

Código

#include <iostream>
#include <vector>

using namespace std;

int main()
{
   int n;
   cin >> n;
   vector<int> a(n);
   vector<int> sum(n);
   int total = 0;
   for (long i = 0; i < n; i++)
   {
      cin >> a[i];
      total += a[i];
      sum[i] = total;
   }
	int res = a[0];
   for (int i = 0; i < n; i++)
   {
	  for (int j = i; j < n; j++) {
	    int current = sum[j] - sum[i] + a[i];
		 res = max(res, current);
	  }
   }
   cout << res << endl; 
   return 0;
}