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

Envío 2161

Problema 0x94 - Subarreglo de máxima suma

  • Autor: Javier
  • Fecha: 2020-11-27 02:30:18 UTC (Hace alrededor de 4 años)
Caso # Resultado Tiempo Memoria
#1
Incorrecto
                      main.cpp:8:16: warning: implicit conversion from 'long' to 'int' changes value from 2147483648 to -2147483648 [-Wconstant-conversion]
    int minv = 2147483648;
        ~~~~   ^~~~~~~~~~
1 warning generated.

                    
0.006 s 1 KBi
#2
Correcto
                      main.cpp:8:16: warning: implicit conversion from 'long' to 'int' changes value from 2147483648 to -2147483648 [-Wconstant-conversion]
    int minv = 2147483648;
        ~~~~   ^~~~~~~~~~
1 warning generated.

                    
0.006 s 1 KBi
#3
Correcto
                      main.cpp:8:16: warning: implicit conversion from 'long' to 'int' changes value from 2147483648 to -2147483648 [-Wconstant-conversion]
    int minv = 2147483648;
        ~~~~   ^~~~~~~~~~
1 warning generated.

                    
0.007 s 1 KBi
#4
Correcto
                      main.cpp:8:16: warning: implicit conversion from 'long' to 'int' changes value from 2147483648 to -2147483648 [-Wconstant-conversion]
    int minv = 2147483648;
        ~~~~   ^~~~~~~~~~
1 warning generated.

                    
0.007 s 1 KBi
#5
Correcto
                      main.cpp:8:16: warning: implicit conversion from 'long' to 'int' changes value from 2147483648 to -2147483648 [-Wconstant-conversion]
    int minv = 2147483648;
        ~~~~   ^~~~~~~~~~
1 warning generated.

                    
0.006 s 1 KBi
#6
Correcto
                      main.cpp:8:16: warning: implicit conversion from 'long' to 'int' changes value from 2147483648 to -2147483648 [-Wconstant-conversion]
    int minv = 2147483648;
        ~~~~   ^~~~~~~~~~
1 warning generated.

                    
0.007 s 1 KBi
#7
Correcto
                      main.cpp:8:16: warning: implicit conversion from 'long' to 'int' changes value from 2147483648 to -2147483648 [-Wconstant-conversion]
    int minv = 2147483648;
        ~~~~   ^~~~~~~~~~
1 warning generated.

                    
0.006 s 1 KBi
#8
Correcto
                      main.cpp:8:16: warning: implicit conversion from 'long' to 'int' changes value from 2147483648 to -2147483648 [-Wconstant-conversion]
    int minv = 2147483648;
        ~~~~   ^~~~~~~~~~
1 warning generated.

                    
0.007 s 1 KBi
#9
Correcto
                      main.cpp:8:16: warning: implicit conversion from 'long' to 'int' changes value from 2147483648 to -2147483648 [-Wconstant-conversion]
    int minv = 2147483648;
        ~~~~   ^~~~~~~~~~
1 warning generated.

                    
0.007 s 1 KBi
#10
Correcto
                      main.cpp:8:16: warning: implicit conversion from 'long' to 'int' changes value from 2147483648 to -2147483648 [-Wconstant-conversion]
    int minv = 2147483648;
        ~~~~   ^~~~~~~~~~
1 warning generated.

                    
0.006 s 1 KBi
#11
Correcto
                      main.cpp:8:16: warning: implicit conversion from 'long' to 'int' changes value from 2147483648 to -2147483648 [-Wconstant-conversion]
    int minv = 2147483648;
        ~~~~   ^~~~~~~~~~
1 warning generated.

                    
0.006 s 1 KBi
#12
Incorrecto
                      main.cpp:8:16: warning: implicit conversion from 'long' to 'int' changes value from 2147483648 to -2147483648 [-Wconstant-conversion]
    int minv = 2147483648;
        ~~~~   ^~~~~~~~~~
1 warning generated.

                    
0.007 s 1 KBi
#13
Incorrecto
                      main.cpp:8:16: warning: implicit conversion from 'long' to 'int' changes value from 2147483648 to -2147483648 [-Wconstant-conversion]
    int minv = 2147483648;
        ~~~~   ^~~~~~~~~~
1 warning generated.

                    
0.006 s 1 KBi
#14
Correcto
                      main.cpp:8:16: warning: implicit conversion from 'long' to 'int' changes value from 2147483648 to -2147483648 [-Wconstant-conversion]
    int minv = 2147483648;
        ~~~~   ^~~~~~~~~~
1 warning generated.

                    
0.007 s 1 KBi
#15
Incorrecto
                      main.cpp:8:16: warning: implicit conversion from 'long' to 'int' changes value from 2147483648 to -2147483648 [-Wconstant-conversion]
    int minv = 2147483648;
        ~~~~   ^~~~~~~~~~
1 warning generated.

                    
0.007 s 1 KBi
#16
Incorrecto
                      main.cpp:8:16: warning: implicit conversion from 'long' to 'int' changes value from 2147483648 to -2147483648 [-Wconstant-conversion]
    int minv = 2147483648;
        ~~~~   ^~~~~~~~~~
1 warning generated.

                    
0.008 s 1 KBi
#17
Incorrecto
                      main.cpp:8:16: warning: implicit conversion from 'long' to 'int' changes value from 2147483648 to -2147483648 [-Wconstant-conversion]
    int minv = 2147483648;
        ~~~~   ^~~~~~~~~~
1 warning generated.

                    
0.057 s 1 KBi
#18
Incorrecto
                      main.cpp:8:16: warning: implicit conversion from 'long' to 'int' changes value from 2147483648 to -2147483648 [-Wconstant-conversion]
    int minv = 2147483648;
        ~~~~   ^~~~~~~~~~
1 warning generated.

                    
0.061 s 1 KBi
#19
Incorrecto
                      main.cpp:8:16: warning: implicit conversion from 'long' to 'int' changes value from 2147483648 to -2147483648 [-Wconstant-conversion]
    int minv = 2147483648;
        ~~~~   ^~~~~~~~~~
1 warning generated.

                    
0.053 s 1 KBi
#20
Incorrecto
                      main.cpp:8:16: warning: implicit conversion from 'long' to 'int' changes value from 2147483648 to -2147483648 [-Wconstant-conversion]
    int minv = 2147483648;
        ~~~~   ^~~~~~~~~~
1 warning generated.

                    
0.061 s 2 KBi
#21
Incorrecto
                      main.cpp:8:16: warning: implicit conversion from 'long' to 'int' changes value from 2147483648 to -2147483648 [-Wconstant-conversion]
    int minv = 2147483648;
        ~~~~   ^~~~~~~~~~
1 warning generated.

                    
0.035 s 2 KBi
#22
Incorrecto
                      main.cpp:8:16: warning: implicit conversion from 'long' to 'int' changes value from 2147483648 to -2147483648 [-Wconstant-conversion]
    int minv = 2147483648;
        ~~~~   ^~~~~~~~~~
1 warning generated.

                    
0.063 s 1 KBi
#23
Correcto
                      main.cpp:8:16: warning: implicit conversion from 'long' to 'int' changes value from 2147483648 to -2147483648 [-Wconstant-conversion]
    int minv = 2147483648;
        ~~~~   ^~~~~~~~~~
1 warning generated.

                    
0.04 s 2 KBi
#24
Incorrecto
                      main.cpp:8:16: warning: implicit conversion from 'long' to 'int' changes value from 2147483648 to -2147483648 [-Wconstant-conversion]
    int minv = 2147483648;
        ~~~~   ^~~~~~~~~~
1 warning generated.

                    
0.03 s 1 KBi
Puntos totales: 50 / 100

Código

#include <iostream>
#include <vector>

using namespace std;

int solve(const vector<int> &a) {
    
    int minv = 2147483648;
    int maxv=-2147483648;
    for (int i = 0; i < a.size(); i++) {
        minv = min(a[i], minv);
        maxv = max(a[i], maxv);
    }
    int best = maxv;
    int current = 0;
    for (int i = 0; i < a.size(); i++)
    {
        current = max(current + a[i], minv);
        best = max(best, current);
    }
    return best;
}

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    int best = solve(a);
    cout << best << endl;
    return 0;
}