Cost Of Balloons


C Solution:
  1.  #include<stdio.h>
  2. int main( ){
  3.    long int tc,g,p,sum,n,t1,t2;
  4.    scanf("%ld",&tc);
  5.    for(int i=1;i<=tc;i++){
  6.       scanf("%ld %ld",&g,&p);
  7.       scanf("%ld",&n);
  8.       for(int j=1;j<=n;j++){
  9.          if(i%2==1){
  10. scanf("%ld %ld",&t1,&t2);
  11.        sum=sum+(t1*g)+(t2*p);
  12.          }
  13.        else{
  14. scanf("%ld %ld",&t1,&t2);
  15.        sum=sum+(t1*p)+(t2*g);
  16.        }
  17.       }
  18.       printf("%d\n",sum);

  19.       sum=0;

  20.    }
  21.    return 0;
  22. }
C++ Solution:

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int T;
  6. cin>>T;
  7. while(T--)
  8. {
  9. int C1, C2;       
  10. cin>>C1>>C2;
  11. int n;     
  12. cin>>n;
  13. int cost = 0;
  14. int a[n][2];   
  15. for(int i=0; i<n; i++)
  16. {
  17. for(int j=0; j<2; j++)
  18. {
  19. cin>>a[i][j];
  20. }
  21. }
  22. for(int i=0; i<n; i++)
  23. {
  24. if(a[i][0]==1)
  25. {
  26. cost = cost + 1*C1;
  27. }
  28. if(a[i][1]==1)
  29. {
  30. cost = cost + 1*C2;
  31. }
  32. }
  33. int cost2=0;
  34. for(int i=0; i<n; i++)
  35. {
  36. if(a[i][0]==1)
  37. {
  38. cost2 = cost2 + 1*C2;
  39. }
  40. if(a[i][1]==1)
  41. {
  42. cost2 = cost2 + 1*C1;
  43. }
  44. }
  45. cout<<min(cost, cost2)<<endl;
  46. }
  47. return 0;
  48. }

Note:
       We Are Providing Every Content in this Blog Inspired From Many People and Provide it Open To All People Who Are Willing Gain Some Stuff in Computer Science.

Comment Below👇 If You Find Better Solution Than Above Solution.