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:

- Use green-colored balloons for the first problem and purple-colored balloons for the second problem
- 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.

`#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';

}

}

## 0 Comments