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

Envío 3539

Problema 0x25 - Suma de un subarreglo grande

  • Autor: toroduque
  • Fecha: 2021-03-21 09:32:29 UTC (Hace más de 3 años)
Caso # Resultado Tiempo Memoria
#1
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:15
    subTotalsArray.push(currentSum)
                   ^

TypeError: Cannot read property 'push' of undefined
    at sumSubTotals (/box/script.js:15:20)
    at Interface.<anonymous> (/box/script.js:30:3)
    at Interface.emit (events.js:210:5)
    at Interface._onLine (readline.js:316:10)
    at Interface._normalWrite (readline.js:461:12)
    at ReadStream.ondata (readline.js:172:10)
    at ReadStream.emit (events.js:210:5)
    at addChunk (_stream_readable.js:309:12)
    at readableAddChunk (_stream_readable.js:290:11)
    at ReadStream.Readable.push (_stream_readable.js:224:10)
0.071 s 7 KBi
#2
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:15
    subTotalsArray.push(currentSum)
                   ^

TypeError: Cannot read property 'push' of undefined
    at sumSubTotals (/box/script.js:15:20)
    at Interface.<anonymous> (/box/script.js:30:3)
    at Interface.emit (events.js:210:5)
    at Interface._onLine (readline.js:316:10)
    at Interface._normalWrite (readline.js:461:12)
    at ReadStream.ondata (readline.js:172:10)
    at ReadStream.emit (events.js:210:5)
    at addChunk (_stream_readable.js:309:12)
    at readableAddChunk (_stream_readable.js:290:11)
    at ReadStream.Readable.push (_stream_readable.js:224:10)
0.067 s 7 KBi
#3
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:15
    subTotalsArray.push(currentSum)
                   ^

TypeError: Cannot read property 'push' of undefined
    at sumSubTotals (/box/script.js:15:20)
    at Interface.<anonymous> (/box/script.js:30:3)
    at Interface.emit (events.js:210:5)
    at Interface._onLine (readline.js:316:10)
    at Interface._normalWrite (readline.js:461:12)
    at ReadStream.ondata (readline.js:172:10)
    at ReadStream.emit (events.js:210:5)
    at addChunk (_stream_readable.js:309:12)
    at readableAddChunk (_stream_readable.js:290:11)
    at ReadStream.Readable.push (_stream_readable.js:224:10)
0.063 s 7 KBi
#4
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:15
    subTotalsArray.push(currentSum)
                   ^

TypeError: Cannot read property 'push' of undefined
    at sumSubTotals (/box/script.js:15:20)
    at Interface.<anonymous> (/box/script.js:30:3)
    at Interface.emit (events.js:210:5)
    at Interface._onLine (readline.js:316:10)
    at Interface._normalWrite (readline.js:461:12)
    at ReadStream.ondata (readline.js:172:10)
    at ReadStream.emit (events.js:210:5)
    at addChunk (_stream_readable.js:309:12)
    at readableAddChunk (_stream_readable.js:290:11)
    at ReadStream.Readable.push (_stream_readable.js:224:10)
0.041 s 7 KBi
#5
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:15
    subTotalsArray.push(currentSum)
                   ^

TypeError: Cannot read property 'push' of undefined
    at sumSubTotals (/box/script.js:15:20)
    at Interface.<anonymous> (/box/script.js:30:3)
    at Interface.emit (events.js:210:5)
    at Interface._onLine (readline.js:316:10)
    at Interface._normalWrite (readline.js:461:12)
    at ReadStream.ondata (readline.js:172:10)
    at ReadStream.emit (events.js:210:5)
    at addChunk (_stream_readable.js:309:12)
    at readableAddChunk (_stream_readable.js:290:11)
    at ReadStream.Readable.push (_stream_readable.js:224:10)
0.097 s 33 KBi
#6
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:15
    subTotalsArray.push(currentSum)
                   ^

TypeError: Cannot read property 'push' of undefined
    at sumSubTotals (/box/script.js:15:20)
    at Interface.<anonymous> (/box/script.js:30:3)
    at Interface.emit (events.js:210:5)
    at Interface._onLine (readline.js:316:10)
    at Interface._normalWrite (readline.js:461:12)
    at ReadStream.ondata (readline.js:172:10)
    at ReadStream.emit (events.js:210:5)
    at addChunk (_stream_readable.js:309:12)
    at readableAddChunk (_stream_readable.js:290:11)
    at ReadStream.Readable.push (_stream_readable.js:224:10)
0.061 s 7 KBi
#7
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:15
    subTotalsArray.push(currentSum)
                   ^

TypeError: Cannot read property 'push' of undefined
    at sumSubTotals (/box/script.js:15:20)
    at Interface.<anonymous> (/box/script.js:30:3)
    at Interface.emit (events.js:210:5)
    at Interface._onLine (readline.js:316:10)
    at Interface._normalWrite (readline.js:461:12)
    at ReadStream.ondata (readline.js:172:10)
    at ReadStream.emit (events.js:210:5)
    at addChunk (_stream_readable.js:309:12)
    at readableAddChunk (_stream_readable.js:290:11)
    at ReadStream.Readable.push (_stream_readable.js:224:10)
0.072 s 6 KBi
#8
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:15
    subTotalsArray.push(currentSum)
                   ^

TypeError: Cannot read property 'push' of undefined
    at sumSubTotals (/box/script.js:15:20)
    at Interface.<anonymous> (/box/script.js:30:3)
    at Interface.emit (events.js:210:5)
    at Interface._onLine (readline.js:316:10)
    at Interface._normalWrite (readline.js:461:12)
    at ReadStream.ondata (readline.js:172:10)
    at ReadStream.emit (events.js:210:5)
    at addChunk (_stream_readable.js:309:12)
    at readableAddChunk (_stream_readable.js:290:11)
    at ReadStream.Readable.push (_stream_readable.js:224:10)
0.073 s 7 KBi
#9
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:15
    subTotalsArray.push(currentSum)
                   ^

TypeError: Cannot read property 'push' of undefined
    at sumSubTotals (/box/script.js:15:20)
    at Interface.<anonymous> (/box/script.js:30:3)
    at Interface.emit (events.js:210:5)
    at Interface._onLine (readline.js:316:10)
    at Interface._normalWrite (readline.js:461:12)
    at ReadStream.ondata (readline.js:172:10)
    at ReadStream.emit (events.js:210:5)
    at addChunk (_stream_readable.js:309:12)
    at readableAddChunk (_stream_readable.js:290:11)
    at ReadStream.Readable.push (_stream_readable.js:224:10)
0.063 s 9 KBi
#10
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:15
    subTotalsArray.push(currentSum)
                   ^

TypeError: Cannot read property 'push' of undefined
    at sumSubTotals (/box/script.js:15:20)
    at Interface.<anonymous> (/box/script.js:30:3)
    at Interface.emit (events.js:210:5)
    at Interface._onLine (readline.js:316:10)
    at Interface._normalWrite (readline.js:461:12)
    at ReadStream.ondata (readline.js:172:10)
    at ReadStream.emit (events.js:210:5)
    at addChunk (_stream_readable.js:309:12)
    at readableAddChunk (_stream_readable.js:290:11)
    at ReadStream.Readable.push (_stream_readable.js:224:10)
0.075 s 10 KBi
#11
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:15
    subTotalsArray.push(currentSum)
                   ^

TypeError: Cannot read property 'push' of undefined
    at sumSubTotals (/box/script.js:15:20)
    at Interface.<anonymous> (/box/script.js:30:3)
    at Interface.emit (events.js:210:5)
    at Interface._onLine (readline.js:316:10)
    at Interface._normalWrite (readline.js:461:12)
    at ReadStream.ondata (readline.js:172:10)
    at ReadStream.emit (events.js:210:5)
    at addChunk (_stream_readable.js:309:12)
    at readableAddChunk (_stream_readable.js:290:11)
    at ReadStream.Readable.push (_stream_readable.js:224:10)
0.072 s 9 KBi
#12
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:15
    subTotalsArray.push(currentSum)
                   ^

TypeError: Cannot read property 'push' of undefined
    at sumSubTotals (/box/script.js:15:20)
    at Interface.<anonymous> (/box/script.js:30:3)
    at Interface.emit (events.js:210:5)
    at Interface._onLine (readline.js:316:10)
    at Interface._normalWrite (readline.js:461:12)
    at ReadStream.ondata (readline.js:172:10)
    at ReadStream.emit (events.js:210:5)
    at addChunk (_stream_readable.js:309:12)
    at readableAddChunk (_stream_readable.js:290:11)
    at ReadStream.Readable.push (_stream_readable.js:224:10)
0.063 s 10 KBi
#13
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:15
    subTotalsArray.push(currentSum)
                   ^

TypeError: Cannot read property 'push' of undefined
    at sumSubTotals (/box/script.js:15:20)
    at Interface.<anonymous> (/box/script.js:30:3)
    at Interface.emit (events.js:210:5)
    at Interface._onLine (readline.js:316:10)
    at Interface._normalWrite (readline.js:461:12)
    at ReadStream.ondata (readline.js:172:10)
    at ReadStream.emit (events.js:210:5)
    at addChunk (_stream_readable.js:309:12)
    at readableAddChunk (_stream_readable.js:290:11)
    at ReadStream.Readable.push (_stream_readable.js:224:10)
0.077 s 10 KBi
#14
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:15
    subTotalsArray.push(currentSum)
                   ^

TypeError: Cannot read property 'push' of undefined
    at sumSubTotals (/box/script.js:15:20)
    at Interface.<anonymous> (/box/script.js:30:3)
    at Interface.emit (events.js:210:5)
    at Interface._onLine (readline.js:316:10)
    at Interface._normalWrite (readline.js:461:12)
    at ReadStream.ondata (readline.js:172:10)
    at ReadStream.emit (events.js:210:5)
    at addChunk (_stream_readable.js:309:12)
    at readableAddChunk (_stream_readable.js:290:11)
    at ReadStream.Readable.push (_stream_readable.js:224:10)
0.16 s 10 KBi
Puntos totales: 0 / 100

Código

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

let lineCounter = 0;
let subTotalsArray;

function sumSubTotals(initialArray) {
  let currentSum = 0;
  for(let i = 0; i < initialArray.length; i++)
  {
    currentSum = currentSum + i
    subTotalsArray.push(currentSum)
  }
}

function sumSubArray(fromIndex, toIndex){
  const fromTotal = subTotalsArray[fromIndex - 1];
  const toTotal = subTotalsArray[toIndex]
  return toTotal - fromTotal
}

rl.on("line", (line) => {
 lineCounter++;
 if (lineCounter === 2) {
  // Run the initial algorithm
  const initialArray = line.split(" ").map(Number);
  sumSubTotals(initialArray)
 }

 if (lineCounter > 3) {
   // these are the inputs Q & P
   const [Q, P] = line.split(" ").map(Number);
   console.log(sumSubArray(Q, P))
 }
})