Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.078 s | 12 KBi |
#2 |
Correcto
|
0.062 s | 6 KBi |
#3 |
Correcto
|
0.033 s | 7 KBi |
#4 |
Correcto
|
0.072 s | 7 KBi |
#5 |
Correcto
|
0.034 s | 7 KBi |
#6 |
Correcto
|
0.061 s | 8 KBi |
#7 |
Correcto
|
0.063 s | 7 KBi |
#8 |
Correcto
|
0.273 s | 16 KBi |
#9 |
Correcto
|
0.533 s | 31 KBi |
#10 |
Correcto
|
0.555 s | 32 KBi |
#11 |
Tiempo límite excedido
|
1.026 s | 33 KBi |
#12 |
Correcto
|
0.775 s | 30 KBi |
#13 |
Correcto
|
0.537 s | 31 KBi |
#14 |
Correcto
|
0.89 s | 31 KBi |
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 let sumsArray = [] for(let i = 0; i < initialArray.length; i++) { currentSum = initialArray[i] + currentSum; sumsArray.push(currentSum); } return sumsArray } const sumSubArray = (fromIndex, toIndex) => { if (fromIndex === 0) return subTotalsArray[toIndex] return subTotalsArray[toIndex] - subTotalsArray[fromIndex - 1]; } 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)) } })