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

Envío 3542

Problema 0x25 - Suma de un subarreglo grande

  • Autor: toroduque
  • Fecha: 2021-03-21 09:37:41 UTC (Hace alrededor de 3 años)
Caso # Resultado Tiempo Memoria
#1
Incorrecto
0.08 s 8 KBi
#2
Incorrecto
0.054 s 7 KBi
#3
Incorrecto
0.061 s 7 KBi
#4
Incorrecto
0.068 s 7 KBi
#5
Incorrecto
0.059 s 7 KBi
#6
Incorrecto
0.065 s 8 KBi
#7
Incorrecto
0.083 s 7 KBi
#8
Incorrecto
0.418 s 15 KBi
#9
Tiempo límite excedido
1.006 s 31 KBi
#10
Tiempo límite excedido
1.021 s 32 KBi
#11
Tiempo límite excedido
1.013 s 32 KBi
#12
Tiempo límite excedido
1.068 s 31 KBi
#13
Incorrecto
0.953 s 32 KBi
#14
Incorrecto
0.961 s 32 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 totalsArray = []
  let currentSum = 0;
  for(let i = 0; i < initialArray.length; i++)
  {
    currentSum = currentSum + i
    totalsArray.push(currentSum)
  }

  return totalsArray
}

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);
  subTotalsArray = sumSubTotals(initialArray)
 }

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