Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*You are conducting a competition at your college. This competition consists of two problems
- and “N” participants. You know the problem that a participant will solve during the contest.
- You provide a ball to a participant after he/she solves a problem. There are only red and green
- colored balls available in a market. Each problem must have a ball associated with it as a prize
- for solving that particular problem. You can distribute balls to each participant by performing
- the following operation:
- 1. Use red-colored balls for the first problem and green-colored balls for the second problem.
- 2. Use green-colored balls for the first problem and red-colored balls for the second problem.
- You are given the cost of each ball and problems that each participant solve. Your task is to
- print the minimum price that you have to pay while purchasing the colored balls.
- Input
- First line: “T” that denotes the number of test cases.
- For each test case:
- i) First line: Cost of red and green-colored balls
- ii) Second line: “N” that denotes the number of participants.
- iii) Next n lines: Contain the status of users. For example, if the value of the j
- th integer in
- the i
- th row is 0, then it depicts that the i
- th participant has not solved the j
- th problem.
- Similarly, if the value of the j
- th integer in the i
- th row is 1, then it depicts that
- the i
- th participant has solved the j
- th problem.
- Output
- For each test case, print the minimum cost that you have to pay to purchase balls*/
- /*aLSO available on Pastebin.com*/
- /*input
- 2
- 9 6
- 3
- 1 1
- 1 1
- 1 0
- 3 4
- 2
- 1 0
- 0 0
- output
- 36
- 3*/
- #include<stdio.h>
- #include<stdlib.h>
- int main()
- { int test_case,stud,i,red,green, minimum_price;
- int ques1,ques2,max1,max2,costly,cheap;
- printf("Enter number of test cases: \n");
- scanf("%d",&test_case);
- while(test_case)
- {
- test_case--;
- max1 = 0; max2 = 0;
- printf("\nPlease enter prices of red and green balls: ");
- scanf("%d %d",&red,&green);
- /*checking which ball is costly*/
- costly = red >= green? red:green;
- cheap = red >= green? green:red;
- printf("\nPlease enter number of students: ");
- scanf("%d",&stud);
- printf("\nEnter result for %d students. if correct press '1' and '0' otherwise: ",stud);
- for(i=0;i<stud;i++)
- {
- printf("\nstudent %d: ",i+1);
- scanf("%d %d",&ques1,&ques2);
- /*checking which question has been solved for majority of student*/
- if(ques1==1)
- max1++;
- if (ques2 == 1)
- max2++;
- }
- if(max1 <= max2)
- minimum_price = max2 * cheap + max1 * costly;
- else
- minimum_price = max1 * cheap + max2 * costly;
- printf("\nMinimum Price = %d",minimum_price);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement