Header Ads Widget

Ticker

6/recent/ticker-posts

Cost of balloons

Problem:-

You are conducting a contest at your college. This contest consists of two problems and n 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:
  1. Use green-colored balloons for the first problem and purple-colored balloons for the second problem
  2. 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: T that denotes the number of test cases (1T10)
  • For each test case: 
    • First line: Cost of green and purple-colored balloons 
    • Second line: n that denotes the number of participants (1n10)
  • Next n lines: Contain the status of users. For example, if the value of the jth integer in the ith row is 0, then it depicts that the ith participant has not solved the jth problem. Similarly, if the value of the jth integer in the ith row is 1, then it depicts that the ith participant has solved the jth 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
SAMPLE OUTPUT
69

14

Solution:-

               Here we take price of greeen ballooons in g and price of purple in p. For solving this 
problem we first we give the green colour for first and purple colour for second question if student able to solve question i.e if input is 1 .and store total price in sum1 and then again we give the purple  colour for first question and green colour for second question and store total price in sum2 .Then check which is minimum.After finding minimum print the min.
#include<stdio.h>
int main()
{
int t,n,g,p,a[10][2],sum1,sum2,ans;
scanf("%d",&t);
for(int i=0;i<t;i++)
{
sum1=sum2=0;
scanf("%d%d",&g,&p);
scanf("%d",&n);
for(int j=0;j<n;j++)
{
for(int k=0;k<2;k++)
scanf("%d",&a[j][k]);
}
for(int j=0;j<n;j++)
{
if(a[j][0]==1)
sum1=sum1+g;
if(a[j][1]==1)
sum1=sum1+p;
}
for(int j=0;j<n;j++)
{
if(a[j][0]==1)
sum2=sum2+p;
if(a[j][1]==1)
sum2=sum2+g;
}
ans=sum1>sum2?sum2:sum1;
printf("%d\n",ans);
}
}






Post a Comment

4 Comments

  1. no_of_test_cases=int(input("no of test casses"))
    n1,n2=input().split()
    cost_of_green=int(n1)
    cost_of_purple=int(n2)
    min_cost=min(cost_of_green,cost_of_purple)
    max_cost=max(cost_of_green,cost_of_purple)

    no_of_participents=int(input())
    test_cases=[]
    total1=0
    list1=[]
    list2=[]
    for i in range(no_of_participents*2):
    test_cases.append(int(input("enter teh test cases")))
    list1=test_cases[0: :2]
    list2=test_cases[1: :2]
    no_of_ones_list1=list1.count(1)
    no_of_ones_list2=list2.count(1)
    min_of_ones=min(no_of_ones_list1,no_of_ones_list2)
    max_of_ones=max(no_of_ones_list1,no_of_ones_list2)
    total1=min_cost*max_of_ones+max_cost*min_of_ones
    print(total1)

    ReplyDelete
  2. #include
    int main(){
    int T,n,cg,cp,count1,count2,ar[10][2];;
    scanf("%d",&T);
    for(int i=0;i<T;i++){
    scanf("%d %d",&cg,&cp);
    scanf("%d",&n);
    count1=0;
    count2=0;
    for(int i=0;i<n;i++){
    for(int j=1;j<2;j++){
    scanf("%d",ar[i][j]);
    }
    }

    for(int i=0;i<n;i++){
    for(int j=0;j<1;j++){
    if(ar[i][j]==1)
    count1=count1+1;
    }
    }
    for(int i=0;i<n;i++){
    for(int j=1;j<2;j++){
    if(ar[i][j]==1){
    count2=count2+1;
    }
    }
    }




    int price1;
    int price2;
    price1=count1*cg+count2*cp;
    price2= count1*cp+count2*cg;
    if(price1<price2){
    printf("%d",price1);
    }
    else printf("%d",price2);



    }
    return 0;



    WHAT IS WRONG WITH THIS CODE

    ReplyDelete
    Replies
    1. there are many syntax errors in your code...I give you your code after correcting the syntax errors ..You have to check your logic is it correct or not

      #include
      int main()
      {
      int T,n,cg,cp,count1,count2,ar[10][2];
      scanf("%d",&T);
      for(int i=0;i<T;i++)
      {
      scanf("%d %d",&cg,&cp);
      scanf("%d",&n);
      count1=0;
      count2=0;
      for(int i=0;i<n;i++)
      {
      for(int j=1;j<2;j++)
      {
      scanf("%d",&ar[i][j]);
      }
      }

      for(int i=0;i<n;i++)
      {
      for(int j=0;j<1;j++)
      {
      if(ar[i][j]==1)
      count1=count1+1;
      }
      }
      for(int i=0;i<n;i++)
      {
      for(int j=1;j<2;j++)
      {
      if(ar[i][j]==1)
      count2=count2+1;
      }
      }

      int price1;
      int price2;
      price1=count1*cg+count2*cp;
      price2= count1*cp+count2*cg;
      if(price1<price2){
      printf("%d",price1);
      }
      else printf("%d",price2);
      }
      return 0;
      }


      Delete