You are viewing a single comment's thread. Return to all comments →
Hi, I am using JavaScript. I keep getting wrong output. Can anyone help with that. Thanks.
"use strict";
process.stdin.resume(); process.stdin.setEncoding("utf-8");
let inputString = ""; let currentLine = 0;
process.stdin.on("data", function (inputStdin) { inputString += inputStdin; });
process.stdin.on("end", function () { inputString = inputString.split("\n");
main();
});
function readLine() { return inputString[currentLine++]; }
function main() { const n = parseInt(readLine().trim(), 10);
const genes = readLine().replace(/\s+$/g, "").split(" "); const health = readLine().replace(/\s+$/g, "").split(" ").map(healthTemp => parseInt(healthTemp, 10)); const s = parseInt(readLine().trim(), 10); let minTotalHealth = Infinity; let maxTotalHealth = -Infinity; for (let sItr = 0; sItr < s; sItr++) { const [first, last, d] = readLine().replace(/\s+$/g, "").split(" "); let totalHealth = 0; for (let i = parseInt(first, 10); i <= parseInt(last, 10); i++) { const gene = genes[i]; const index = genes.indexOf(gene); if (index !== -1) { totalHealth += health[index]; } } minTotalHealth = Math.min(minTotalHealth, totalHealth); maxTotalHealth = Math.max(maxTotalHealth, totalHealth); } console.log(``${minTotalHealth} $`{maxTotalHealth}`);
}
Seems like cookies are disabled on this browser, please enable them to open this website
Determining DNA Health
You are viewing a single comment's thread. Return to all comments →
Hi, I am using JavaScript. I keep getting wrong output. Can anyone help with that. Thanks.
"use strict";
process.stdin.resume(); process.stdin.setEncoding("utf-8");
let inputString = ""; let currentLine = 0;
process.stdin.on("data", function (inputStdin) { inputString += inputStdin; });
process.stdin.on("end", function () { inputString = inputString.split("\n");
});
function readLine() { return inputString[currentLine++]; }
function main() { const n = parseInt(readLine().trim(), 10);
}