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

Envío 2779

Problema 0xf2 - Partir un arreglo grande en 2

  • Autor: hamorillo
  • Fecha: 2021-02-04 16:11:43 UTC (Hace casi 4 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.18 s 12 KBi
#2
Correcto
0.169 s 16 KBi
#3
Correcto
0.166 s 15 KBi
#4
Correcto
0.189 s 12 KBi
#5
Correcto
0.154 s 16 KBi
#6
Correcto
0.158 s 15 KBi
#7
Correcto
0.166 s 16 KBi
#8
Correcto
0.179 s 16 KBi
#9
Correcto
0.168 s 16 KBi
#10
Correcto
0.179 s 16 KBi
#11
Correcto
0.184 s 13 KBi
#12
Correcto
0.269 s 14 KBi
#13
Correcto
0.244 s 18 KBi
#14
Error en tiempo de ejecución (NZEC)
Exited with error status 137
run: line 1:     3 Killed                  /usr/local/openjdk13/bin/java Main
0.917 s 125 KBi
#15
Error en tiempo de ejecución (NZEC)
Exited with error status 137
run: line 1:     3 Killed                  /usr/local/openjdk13/bin/java Main
0.893 s 125 KBi
#16
Error en tiempo de ejecución (NZEC)
Exited with error status 137
run: line 1:     3 Killed                  /usr/local/openjdk13/bin/java Main
0.86 s 125 KBi
#17
Error en tiempo de ejecución (NZEC)
Exited with error status 137
run: line 1:     3 Killed                  /usr/local/openjdk13/bin/java Main
0.882 s 125 KBi
#18
Error en tiempo de ejecución (NZEC)
Exited with error status 137
run: line 1:     3 Killed                  /usr/local/openjdk13/bin/java Main
0.917 s 125 KBi
#19
Error en tiempo de ejecución (NZEC)
Exited with error status 137
run: line 1:     3 Killed                  /usr/local/openjdk13/bin/java Main
0.865 s 125 KBi
#20
Error en tiempo de ejecución (NZEC)
Exited with error status 137
run: line 1:     3 Killed                  /usr/local/openjdk13/bin/java Main
0.986 s 125 KBi
Puntos totales: 65 / 100

Código

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Data data = readNumsFromStdin();

        long totalSum = calculateTotalSum(data.numbers);
        long leftSum = 0;
        long rightSum = totalSum;

        for (int i = 0; i < data.totalNumbers - 1; i++) {
            leftSum += data.numbers[i];
            rightSum -= data.numbers[i];

            if (leftSum > 0 && rightSum < 0) {
                System.out.println(i + 1);
                return;
            }
        }

        System.out.println("Impossible");
    }

    private static long calculateTotalSum(int[] numbers) {
        long sum = 0;

        for (int num : numbers) {
            sum += num;
        }
        return sum;
    }

    private static Data readNumsFromStdin() {
        Data data = new Data();
        Scanner in = new Scanner(System.in);

        data.totalNumbers = in.nextInt();
        data.numbers = new int[data.totalNumbers];
        readArrayFromStdin(data.numbers, data.totalNumbers, in);

        return data;
    }

    private static void readArrayFromStdin(int[] array, int count, Scanner in) {
        for (int i = 0; i < count; i++) {
            array[i] = in.nextInt();
        }
    }

    private static class Data {
        int totalNumbers;
        int[] numbers;
    }
}