Cost of balloons
Practice
3.8 (750 votes)
Basic programming
Easy
Input/output
Problem
83% Success 93688 Attempts 10 Points 1s Time Limit 256MB Memory 1024 KB Max Code

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 (\(1 \le T \le 10\))
  • For each test case: 
    • First line: Cost of green and purple-colored balloons 
    • Second line: \(n\) that denotes the number of participants (\(1 \le n \le 10\))
  • Next \(n\) lines: Contain the status of users. For example, if the value of the \(j^{th}\) integer in the \(i^{th}\) row is \(0\), then it depicts that the \(i^{th}\) participant has not solved the \(j^{th}\) problem. Similarly, if the value of the \(j^{th}\) integer in the \(i^{th}\) row is \(1\), then it depicts that the \(i^{th}\) participant has solved the \(j^{th}\) problem.

Output format
For each test case, print the minimum cost that you have to pay to purchase balloons.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:10
2080 votes
Tags:
Easy
Points:10
455 votes
Tags:
Basic ProgrammingEasyInput/Output
Points:10
1585 votes
Tags:
Easy