Skip to content
Programmingoneonone
Programmingoneonone
  • Engineering Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
    • 100+ C++ Programs
  • Solutions
    • HackerRank
      • Algorithms Solutions
      • C solutions
      • C++ solutions
      • Java solutions
      • Python solutions
    • Leetcode Solutions
    • HackerEarth Solutions
  • Work with US
Programmingoneonone
Programmingoneonone

HackerEarth Cost of balloons problem solution

YASH PAL, 31 July 202413 February 2026
In this HackerEarth Cost of balloons problem solution, 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 the 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 the problems that each participant solves. Your task is to print the minimum price that you have to pay while purchasing balloons.
 
 
hackerEarth Cost of balloons problem solution
 
 

HackerEarth Cost of balloons problem solution.

#include <bits/stdc++.h>
using namespace std;

const int maxn = 2;
int t, n, cost[maxn], used[maxn], ph[maxn], pu[maxn], ans[maxn];
int main(){
ios::sync_with_stdio(0), cin.tie(0);
cin >> t;
while(t--){
used[0] = used[1] = 0;
for(int i = 0; i < maxn; i++)
cin >> cost[i];
cin >> n;
for(int i = 0; i < n; i++)
for(int j = 0; j < maxn; j++){
int x;
cin >> x;
used[j] += x;
}
cout << min(cost[0] * used[0] + cost[1] * used[1], cost[1] * used[0] + cost[0] * used[1]) << 'n';
}
}
 
 
coding problems solutions HackerEarth HackerEarth

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

Programmingoneonone

We at Programmingoneonone, also known as Programming101 is a learning hub of programming and other related stuff. We provide free learning tutorials/articles related to programming and other technical stuff to people who are eager to learn about it.

Pages

  • About US
  • Contact US
  • Privacy Policy

Practice

  • Java
  • C++
  • C

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes