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

Envío 6187

Problema 0xf2 - Partir un arreglo grande en 2

  • Autor: rpedrazacoello
  • Fecha: 2022-05-25 04:17:06 UTC (Hace casi 2 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.083 s 16 KBi
#2
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Exception in thread "main" java.lang.NullPointerException
	at Main.main(Main.java:30)
0.087 s 16 KBi
#3
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Exception in thread "main" java.lang.NullPointerException
	at Main.main(Main.java:30)
0.082 s 16 KBi
#4
Correcto
0.086 s 16 KBi
#5
Correcto
0.085 s 16 KBi
#6
Correcto
0.082 s 16 KBi
#7
Correcto
0.09 s 16 KBi
#8
Correcto
0.082 s 16 KBi
#9
Correcto
0.081 s 16 KBi
#10
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Exception in thread "main" java.lang.NullPointerException
	at Main.main(Main.java:30)
0.085 s 16 KBi
#11
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Exception in thread "main" java.lang.NullPointerException
	at Main.main(Main.java:30)
0.086 s 16 KBi
#12
Correcto
0.154 s 19 KBi
#13
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Exception in thread "main" java.lang.NullPointerException
	at Main.main(Main.java:30)
0.11 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.519 s 125 KBi
#15
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Exception in thread "main" java.lang.NullPointerException
	at Main.main(Main.java:30)
0.766 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.54 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.463 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.603 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.48 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.571 s 125 KBi
Puntos totales: 40 / 100

Código

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();

        long totalCount = 0;
        HashMap<Integer, Long> leftPositive = new HashMap<>();
        ArrayList<Integer> leftPositiveIndexes = new ArrayList<>();

        long oldTotalCount=0;
        for(int i=0; i<n; i++){
            int x = scanner.nextInt();
            totalCount+=x;

            if(totalCount > 0){
                if(oldTotalCount<totalCount){
                    oldTotalCount = totalCount;
                    leftPositiveIndexes.add(i);
                    leftPositive.put(i, totalCount);
                }
            }
        }

        boolean flag = true;
        for(int i=0; i<leftPositiveIndexes.size(); i++){
            long left = leftPositive.get(i);
            long right = totalCount - left;

            if(right < 0){
                System.out.println(leftPositiveIndexes.get(i)+1);
                flag = false;
                break;
            }
        }

        if(flag){
            System.out.println("Impossible");
        }
    }
}