Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.059 s | 6 KBi |
#2 |
Correcto
|
0.034 s | 7 KBi |
#3 |
Correcto
|
0.059 s | 7 KBi |
#4 |
Correcto
|
0.046 s | 6 KBi |
#5 |
Correcto
|
0.033 s | 7 KBi |
#6 |
Correcto
|
0.038 s | 8 KBi |
#7 |
Correcto
|
0.083 s | 7 KBi |
#8 |
Correcto
|
0.521 s | 16 KBi |
#9 |
Correcto
|
0.943 s | 31 KBi |
#10 |
Correcto
|
0.533 s | 32 KBi |
#11 |
Tiempo límite excedido
|
1.081 s | 35 KBi |
#12 |
Correcto
|
0.97 s | 32 KBi |
#13 |
Correcto
|
0.583 s | 31 KBi |
#14 |
Correcto
|
0.974 s | 32 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)) } })