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

Envío 3315

Problema 0xf2 - Partir un arreglo grande en 2

  • Autor: datruq
  • Fecha: 2021-03-09 07:06:58 UTC (Hace alrededor de 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.156 s 16 KBi
#2
Correcto
0.176 s 15 KBi
#3
Incorrecto
0.154 s 16 KBi
#4
Incorrecto
0.171 s 15 KBi
#5
Correcto
0.16 s 16 KBi
#6
Incorrecto
0.169 s 16 KBi
#7
Tiempo límite excedido
1.088 s 16 KBi
#8
Tiempo límite excedido
1.096 s 16 KBi
#9
Incorrecto
0.158 s 15 KBi
#10
Tiempo límite excedido
1.042 s 16 KBi
#11
Incorrecto
0.175 s 16 KBi
#12
Correcto
0.191 s 16 KBi
#13
Correcto
0.21 s 16 KBi
#14
Incorrecto
0.873 s 86 KBi
#15
Incorrecto
0.828 s 80 KBi
#16
Incorrecto
0.983 s 87 KBi
#17
Incorrecto
0.887 s 86 KBi
#18
Correcto
0.836 s 86 KBi
#19
Tiempo límite excedido
1.096 s 87 KBi
#20
Tiempo límite excedido
1.052 s 102 KBi
Puntos totales: 30 / 100

Código

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sn = new Scanner(System.in);
        int n = Integer.parseInt(sn.nextLine());
        String[] arItems = sn.nextLine().split(" ");
        Integer[] entries = new Integer[n];
        for (int i = 0; i < n; i++) {
            int arItem = Integer.parseInt(arItems[i]);
            entries[i] = arItem;
        }
        int sumLeft = 0;
        int sumRight = 0;
        int newIndex = 1;
        int resposne = 0;
        while (sumRight >= 0){
            sumLeft = 0;
            sumRight = 0;
            for (int i = 0; i <= newIndex; i++) {
                sumLeft = sumLeft + entries[i];
                if (sumLeft > 0 && i == 0) {
                    newIndex = i + 1;
                    resposne = i + 1;
                    break;
                }
                if (sumLeft > 0 && newIndex == i ) {
                    newIndex = i + 1;
                    resposne = i + 1;
                    break;
                }
            }
            if (sumLeft < 0){
                System.out.println("Impossible");
                break;
            }
            for (int i = newIndex; i < n; i++) {
                sumRight = sumRight + entries[i];
            }

            if (sumRight > 0) {
                newIndex++;
            }

            if (newIndex == n && sumRight > 0){
                System.out.println("Impossible");
                break;
            }

            if (newIndex == n) {
                resposne--;
                break;
            }
        }
        System.out.println(resposne);
    }

}