Cost of balloons
Tag(s):

## Basic Programming, Basics of Input/Output, Input/Output, Very-Easy

Problem
Editorial
Analytics

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.

SAMPLE INPUT
2
9 6
10
1 1
1 1
0 1
0 0
0 1
0 0
0 1
0 1
1 1
0 0
1 9
10
0 1
0 0
0 0
0 1
1 0
0 1
0 1
0 0
0 1
0 0

SAMPLE OUTPUT
69
14

Explanation

-

Time Limit: 1,0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: Bash, C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Swift-4.1, TypeScript, Visual Basic

## CODE EDITOR

Initializing Code Editor...

## This Problem was Asked in Challenge Name

June Easy' 19

OTHER PROBLEMS OF THIS CHALLENGE
• Algorithms > Sorting
• Algorithms > Greedy Algorithms
• Algorithms > Graphs
• Math > Basic Geometry
• Algorithms > Graphs
Уведомления

?
{"ft_lang_label":"__label__en","ft_lang_prob":0.8301154,"math_prob":0.95627075,"size":2208,"snap":"2020-10-2020-16","text_gpt3_token_len":630,"char_repetition_ratio":0.14972776,"word_repetition_ratio":0.13953489,"special_character_ratio":0.29846016,"punctuation_ratio":0.14644352,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.98887515,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-02-28T15:55:16Z\",\"WARC-Record-ID\":\"<urn:uuid:37e74b5a-1b91-4eb7-91c9-3fdb595f9103>\",\"Content-Length\":\"114595\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:bf7b4a0a-8b2b-4ef1-849e-f2e929282726>\",\"WARC-Concurrent-To\":\"<urn:uuid:e675d668-77e3-4b5a-800d-0e29ef485ae0>\",\"WARC-IP-Address\":\"52.76.81.127\",\"WARC-Target-URI\":\"https://www.hackerearth.com/ru/practice/basic-programming/input-output/basics-of-input-output/practice-problems/algorithm/mojtaba-prepares-contest-29b2a044/\",\"WARC-Payload-Digest\":\"sha1:BLPHWXN6RQIZSS37GJTDMZVAXC7L6M6G\",\"WARC-Block-Digest\":\"sha1:DXJPKAWJFIKTTKUPE5C73JYZJOB26KMY\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-10/CC-MAIN-2020-10_segments_1581875147234.52_warc_CC-MAIN-20200228135132-20200228165132-00055.warc.gz\"}"}