Cost of balloons

PHOTO EMBED

Sun May 01 2022 10:12:50 GMT+0000 (Coordinated Universal Time)

Saved by @GreenMark #javascript

// 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();

}
content_copyCOPY

Problem You are conducting a contest at your college. This contest consists of two problems and participants. You know the problem that a candidate will solve during the contest. You provide a balloon to a participant after he or she solves a problem. There are only green and purple-colored balloons available in a market. Each problem must have a balloon associated with it as a prize for solving that specific problem. You can distribute balloons to each participant by performing the following operation: Use green-colored balloons for the first problem and purple-colored balloons for the second problem Use purple-colored balloons for the first problem and green-colored balloons for the second problem You are given the cost of each balloon and problems that each participant solve. Your task is to print the minimum price that you have to pay while purchasing balloons. Input format First line: that denotes the number of test cases () For each test case: First line: Cost of green and purple-colored balloons Second line: that denotes the number of participants () Next lines: Contain the status of users. For example, if the value of the integer in the row is , then it depicts that the participant has not solved the problem. Similarly, if the value of the integer in the row is , then it depicts that the participant has solved the problem. Output format For each test case, print the minimum cost that you have to pay to purchase balloons. Sample Input 2 9 6 10 1 1 1 1 0 1 0 0 0 1 0 0 0 1 0 1 1 1 0 0 1 9 10 0 1 0 0 0 0 0 1 1 0 0 1 0 1 0 0 0 1 0 0

https://www.hackerearth.com/practice/basic-programming/input-output/basics-of-input-output/practice-problems/algorithm/mojtaba-prepares-contest-29b2a044/