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

Envío 3538

Problema 0x25 - Suma de un subarreglo grande

  • Autor: toroduque
  • Fecha: 2021-03-21 09:31:11 UTC (Hace alrededor de 3 años)
Caso # Resultado Tiempo Memoria
#1
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:2
const rl = readline.createInterface({
                    ^

TypeError: readline.createInterface is not a function
    at Object.<anonymous> (/box/script.js:2:21)
    at Module._compile (internal/modules/cjs/loader.js:959:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
    at Module.load (internal/modules/cjs/loader.js:815:32)
    at Function.Module._load (internal/modules/cjs/loader.js:727:14)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)
    at internal/main/run_main_module.js:17:11
0.057 s 6 KBi
#2
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:2
const rl = readline.createInterface({
                    ^

TypeError: readline.createInterface is not a function
    at Object.<anonymous> (/box/script.js:2:21)
    at Module._compile (internal/modules/cjs/loader.js:959:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
    at Module.load (internal/modules/cjs/loader.js:815:32)
    at Function.Module._load (internal/modules/cjs/loader.js:727:14)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)
    at internal/main/run_main_module.js:17:11
0.062 s 6 KBi
#3
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:2
const rl = readline.createInterface({
                    ^

TypeError: readline.createInterface is not a function
    at Object.<anonymous> (/box/script.js:2:21)
    at Module._compile (internal/modules/cjs/loader.js:959:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
    at Module.load (internal/modules/cjs/loader.js:815:32)
    at Function.Module._load (internal/modules/cjs/loader.js:727:14)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)
    at internal/main/run_main_module.js:17:11
0.063 s 6 KBi
#4
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:2
const rl = readline.createInterface({
                    ^

TypeError: readline.createInterface is not a function
    at Object.<anonymous> (/box/script.js:2:21)
    at Module._compile (internal/modules/cjs/loader.js:959:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
    at Module.load (internal/modules/cjs/loader.js:815:32)
    at Function.Module._load (internal/modules/cjs/loader.js:727:14)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)
    at internal/main/run_main_module.js:17:11
0.05 s 6 KBi
#5
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:2
const rl = readline.createInterface({
                    ^

TypeError: readline.createInterface is not a function
    at Object.<anonymous> (/box/script.js:2:21)
    at Module._compile (internal/modules/cjs/loader.js:959:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
    at Module.load (internal/modules/cjs/loader.js:815:32)
    at Function.Module._load (internal/modules/cjs/loader.js:727:14)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)
    at internal/main/run_main_module.js:17:11
0.086 s 33 KBi
#6
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:2
const rl = readline.createInterface({
                    ^

TypeError: readline.createInterface is not a function
    at Object.<anonymous> (/box/script.js:2:21)
    at Module._compile (internal/modules/cjs/loader.js:959:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
    at Module.load (internal/modules/cjs/loader.js:815:32)
    at Function.Module._load (internal/modules/cjs/loader.js:727:14)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)
    at internal/main/run_main_module.js:17:11
0.051 s 7 KBi
#7
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:2
const rl = readline.createInterface({
                    ^

TypeError: readline.createInterface is not a function
    at Object.<anonymous> (/box/script.js:2:21)
    at Module._compile (internal/modules/cjs/loader.js:959:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
    at Module.load (internal/modules/cjs/loader.js:815:32)
    at Function.Module._load (internal/modules/cjs/loader.js:727:14)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)
    at internal/main/run_main_module.js:17:11
0.052 s 6 KBi
#8
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:2
const rl = readline.createInterface({
                    ^

TypeError: readline.createInterface is not a function
    at Object.<anonymous> (/box/script.js:2:21)
    at Module._compile (internal/modules/cjs/loader.js:959:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
    at Module.load (internal/modules/cjs/loader.js:815:32)
    at Function.Module._load (internal/modules/cjs/loader.js:727:14)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)
    at internal/main/run_main_module.js:17:11
0.051 s 7 KBi
#9
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:2
const rl = readline.createInterface({
                    ^

TypeError: readline.createInterface is not a function
    at Object.<anonymous> (/box/script.js:2:21)
    at Module._compile (internal/modules/cjs/loader.js:959:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
    at Module.load (internal/modules/cjs/loader.js:815:32)
    at Function.Module._load (internal/modules/cjs/loader.js:727:14)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)
    at internal/main/run_main_module.js:17:11
0.069 s 7 KBi
#10
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:2
const rl = readline.createInterface({
                    ^

TypeError: readline.createInterface is not a function
    at Object.<anonymous> (/box/script.js:2:21)
    at Module._compile (internal/modules/cjs/loader.js:959:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
    at Module.load (internal/modules/cjs/loader.js:815:32)
    at Function.Module._load (internal/modules/cjs/loader.js:727:14)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)
    at internal/main/run_main_module.js:17:11
0.049 s 7 KBi
#11
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:2
const rl = readline.createInterface({
                    ^

TypeError: readline.createInterface is not a function
    at Object.<anonymous> (/box/script.js:2:21)
    at Module._compile (internal/modules/cjs/loader.js:959:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
    at Module.load (internal/modules/cjs/loader.js:815:32)
    at Function.Module._load (internal/modules/cjs/loader.js:727:14)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)
    at internal/main/run_main_module.js:17:11
0.054 s 6 KBi
#12
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:2
const rl = readline.createInterface({
                    ^

TypeError: readline.createInterface is not a function
    at Object.<anonymous> (/box/script.js:2:21)
    at Module._compile (internal/modules/cjs/loader.js:959:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
    at Module.load (internal/modules/cjs/loader.js:815:32)
    at Function.Module._load (internal/modules/cjs/loader.js:727:14)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)
    at internal/main/run_main_module.js:17:11
0.057 s 6 KBi
#13
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:2
const rl = readline.createInterface({
                    ^

TypeError: readline.createInterface is not a function
    at Object.<anonymous> (/box/script.js:2:21)
    at Module._compile (internal/modules/cjs/loader.js:959:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
    at Module.load (internal/modules/cjs/loader.js:815:32)
    at Function.Module._load (internal/modules/cjs/loader.js:727:14)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)
    at internal/main/run_main_module.js:17:11
0.048 s 6 KBi
#14
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:2
const rl = readline.createInterface({
                    ^

TypeError: readline.createInterface is not a function
    at Object.<anonymous> (/box/script.js:2:21)
    at Module._compile (internal/modules/cjs/loader.js:959:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
    at Module.load (internal/modules/cjs/loader.js:815:32)
    at Function.Module._load (internal/modules/cjs/loader.js:727:14)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)
    at internal/main/run_main_module.js:17:11
0.053 s 7 KBi
Puntos totales: 0 / 100

Código

const readline = ('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))
 }
})