Skip to content
Programmingoneonone
Programmingoneonone

Learn everything about programming

  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
    • Cybersecurity
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone
Programmingoneonone

Learn everything about programming

HackerEarth Cost of balloons problem solution

YASH PAL, 31 July 2024
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

Post navigation

Previous post
Next post

Are you a student and stuck with your career or worried about real-time things, and don't know how to manage your learning phase? Which profession to choose? and how to learn new things according to your goal, and land a dream job. Then this might help to you.

Hi My name is YASH PAL, founder of this Blog and a Senior Software engineer with 5+ years of Industry experience. I personally helped 40+ students to make a clear goal in their professional lives. Just book a one-on-one personal call with me for 30 minutes for 300 Rupees. Ask all your doubts and questions related to your career to set a clear roadmap for your professional life.

Book session - https://wa.me/qr/JQ2LAS7AASE2M1

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

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