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

Envío 5099

Problema 0xf2 - Partir un arreglo grande en 2

  • Autor: jarangolp
  • Fecha: 2021-10-14 04:03:16 UTC (Hace alrededor de 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.061 s 6 KBi
#2
Correcto
0.055 s 6 KBi
#3
Correcto
0.05 s 6 KBi
#4
Correcto
0.059 s 7 KBi
#5
Correcto
0.05 s 9 KBi
#6
Correcto
0.051 s 6 KBi
#7
Correcto
0.053 s 9 KBi
#8
Correcto
0.055 s 10 KBi
#9
Correcto
0.076 s 6 KBi
#10
Correcto
0.055 s 6 KBi
#11
Correcto
0.067 s 6 KBi
#12
Correcto
0.057 s 6 KBi
#13
Correcto
0.057 s 6 KBi
#14
Correcto
0.152 s 20 KBi
#15
Correcto
0.111 s 22 KBi
#16
Correcto
0.129 s 19 KBi
#17
Correcto
0.121 s 20 KBi
#18
Correcto
0.145 s 43 KBi
#19
Correcto
0.137 s 20 KBi
#20
Correcto
0.177 s 35 KBi
Puntos totales: 100 / 100

Código

const readline = require('readline');

const rd = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});


rd.question('', n => {
  rd.question('', numbersInput => {
    const numbers = numbersInput.split(' ').map(n => Number(n));
    let finish = false;
    let firstRightElementIndex = 0;
    let totalSum = 0, leftSum = 0;

    for (let i = 0; i < numbers.length; i++) {
      totalSum += numbers[i];
    }

    while (firstRightElementIndex < numbers.length && !finish) {
      const number = numbers[firstRightElementIndex];
      leftSum += number;
      totalSum -= number;
      finish = (leftSum > 0) && (totalSum < 0);
      firstRightElementIndex++;
    }

    if (finish) {
      console.log(firstRightElementIndex);
    } else {
      console.log('Impossible');
    }
    process.exit();
  });
});