// Cost of balloons
// Sample code to perform I/O:
process.stdin.resume();
process.stdin.setEncoding("utf-8");
var stdin_input = "";
process.stdin.on("data", function (input) {
stdin_input += input; // Reading input from STDIN
});
process.stdin.on("end", function () {
main(stdin_input);
});
function main(input) {
process.stdout.write(costBallons(input)); // Writing output to STDOUT
}
// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail
// Write your code here
// Sample code to perform I/O:
//Enter your code here
function costBallons(data) {
data= data.toString().split("\n");
let answer =[];
let ligne = 0;
// Number of test
let tests = Number(data[ligne]);
//console.log("Number of tests ", tests);
ligne = 1;
for (let t=1; t<=tests; t++ ) {
// console.log("Num test : ", t);
// console.log(" ----- Cost ------ ");
let costs = data[ligne].split(" ").map((item)=> Number(item));
//for (let costX = 0; costX<costs.length; costX++) {
// console.log(costs[costX]);
//}
//console.log(" ----- Participants ------ ");
ligne = ligne + 1;
let participants = Number(data[ligne]);
ligne = ligne +1;
//console.log(participants);
let sumColone1=0;
let sumColone2 = 0;
//console.log(" ----- Status ------ ");
for (let status=0; status<participants; status++) {
let stat = data[ligne+status].split(" ").map((item)=> Number(item));
// console.log(stat);
// Calcul somme colonne
sumColone1 = sumColone1 + stat[status,0];
sumColone2 = sumColone2 + stat[status,1];
}
//console.log(sumColone1);
//console.log(sumColone2);
// Cost green and cost purple
costGreen = costs[0];
costPurple = costs[1];
// Case 1
sum1 = costGreen*sumColone1 + costPurple*sumColone2;
//console.log(sum1);
// Case 2
sum2 = costPurple*sumColone1 + costGreen*sumColone2;
//console.log(sum2);
//
answer.push(Math.min(sum1,sum2));
ligne = ligne +participants;
}
//let participants = Number(data[2]);
//let status =
return answer.join("\n").toString();
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter