Advertisement
Mr_kindle

redblue.c

Oct 27th, 2022 (edited)
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.07 KB | None | 0 0
  1. /*You are conducting a competition at your college. This competition consists of two problems
  2. and “N” participants. You know the problem that a participant will solve during the contest.
  3. You provide a ball to a participant after he/she solves a problem. There are only red and green
  4. colored balls available in a market. Each problem must have a ball associated with it as a prize
  5. for solving that particular problem. You can distribute balls to each participant by performing
  6. the following operation:
  7. 1. Use red-colored balls for the first problem and green-colored balls for the second problem.
  8. 2. Use green-colored balls for the first problem and red-colored balls for the second problem.
  9. You are given the cost of each ball and problems that each participant solve. Your task is to
  10. print the minimum price that you have to pay while purchasing the colored balls.
  11. Input
  12.  First line: “T” that denotes the number of test cases.
  13.  For each test case:
  14. i) First line: Cost of red and green-colored balls
  15. ii) Second line: “N” that denotes the number of participants.
  16. iii) Next n lines: Contain the status of users. For example, if the value of the j
  17. th integer in
  18. the i
  19. th row is 0, then it depicts that the i
  20. th participant has not solved the j
  21. th problem.
  22. Similarly, if the value of the j
  23. th integer in the i
  24. th row is 1, then it depicts that
  25. the i
  26. th participant has solved the j
  27. th problem.
  28. Output
  29.  For each test case, print the minimum cost that you have to pay to purchase balls*/
  30.  
  31. /*aLSO available on Pastebin.com*/
  32. /*input
  33. 2
  34. 9 6
  35. 3
  36. 1 1
  37. 1 1
  38. 1 0
  39. 3 4
  40. 2
  41. 1 0
  42. 0 0
  43. output
  44. 36
  45. 3*/
  46.  
  47. #include<stdio.h>
  48. #include<stdlib.h>
  49.  
  50. int main()
  51. {   int test_case,stud,i,red,green, minimum_price;
  52.     int ques1,ques2,max1,max2,costly,cheap;
  53.     printf("Enter number of test cases:  \n");
  54.     scanf("%d",&test_case);
  55.     while(test_case)
  56.         {
  57.            
  58.  
  59.             test_case--;
  60.             max1 = 0; max2 = 0;
  61.             printf("\nPlease enter prices of red and green balls:  ");
  62.             scanf("%d %d",&red,&green);
  63.             /*checking which ball is costly*/
  64.             costly = red >= green? red:green;
  65.             cheap =  red >= green? green:red;
  66.             printf("\nPlease enter number of students:  ");
  67.             scanf("%d",&stud);
  68.             printf("\nEnter result for %d students. if correct press '1' and '0' otherwise:  ",stud);
  69.             for(i=0;i<stud;i++)
  70.                 {
  71.                     printf("\nstudent %d:  ",i+1);
  72.                     scanf("%d %d",&ques1,&ques2);
  73.                     /*checking which question has been solved for majority of student*/
  74.                     if(ques1==1)
  75.                         max1++;
  76.                     if (ques2 == 1)
  77.                         max2++;
  78.  
  79.                 }
  80.                
  81.                 if(max1 <= max2)
  82.                     minimum_price = max2 * cheap + max1 * costly;
  83.                 else
  84.                     minimum_price = max1 * cheap + max2 * costly;
  85.            
  86.             printf("\nMinimum Price = %d",minimum_price);
  87.            
  88.         }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement