Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.057 s | 7 KBi |
#2 |
Correcto
|
0.036 s | 7 KBi |
#3 |
Correcto
|
0.048 s | 19 KBi |
#4 |
Correcto
|
0.042 s | 8 KBi |
#5 |
Correcto
|
0.133 s | 33 KBi |
#6 |
Correcto
|
0.038 s | 7 KBi |
#7 |
Correcto
|
0.069 s | 9 KBi |
#8 |
Correcto
|
0.339 s | 17 KBi |
#9 |
Correcto
|
0.479 s | 30 KBi |
#10 |
Correcto
|
0.676 s | 30 KBi |
#11 |
Correcto
|
0.942 s | 32 KBi |
#12 |
Correcto
|
0.525 s | 31 KBi |
#13 |
Correcto
|
0.499 s | 33 KBi |
#14 |
Correcto
|
0.938 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 = Number(initialArray[i]) + currentSum; sumsArray.push(currentSum); } return sumsArray } const sumSubArray = (fromIndex, toIndex) => { if (Number(fromIndex) === 0) return subTotalsArray[toIndex] return subTotalsArray[Number(toIndex)] - subTotalsArray[Number(fromIndex) - 1]; } rl.on("line", (line) => { ++lineCounter; if (lineCounter === 2) { // Run the initial algorithm const initialArray = line.split(" "); subTotalsArray = sumSubTotals(initialArray) } if (lineCounter > 3) { // these are the inputs Q & P const [Q, P] = line.split(" "); console.log(sumSubArray(Q, P)) } })