#C10087. Auction Revenue Calculation

    ID: 39253 Type: Default 1000ms 256MiB

Auction Revenue Calculation

Auction Revenue Calculation

In this problem, you are given data from multiple auction groups. Each auction has a reserve (base) price and a list of bids. For each auction, only the bids that meet or exceed the reserve price are considered; the highest among them is taken as the winning bid. The total revenue for a test case is the sum of the winning bids from all auctions in that test case. The input consists of one or more groups. Each group starts with an integer T indicating the number of test cases. Each test case starts with an integer m (the number of auctions) followed by m lines where each line contains the auction details. Each auction line contains space-separated integers: the first integer is the base price, the second integer is not used (e.g. number of bidders), and the remaining integers are the bid values. A line with a single zero terminates the input.


The revenue for an auction is determined by choosing the highest bid that is at least as large as the base price. If no bid qualifies, the revenue for that auction is zero. Sum the revenues for all auctions in a test case to get the final answer for that test case.

inputFormat

The input is provided through standard input (stdin). It consists of multiple groups. For each group, the first line is an integer T (the number of test cases in that group). For each test case, the first line is an integer m (the number of auctions), followed by m lines each containing space-separated integers representing an auction. The format for an auction line is:

(b\ n\ bid_1\ bid_2\ \ldots\ bid_k) where (b) is the reserve price and (n) is an extra number (not used).

The input terminates when a line containing a single 0 is encountered.

outputFormat

For each test case, print a single line to standard output (stdout) with the total revenue computed as the sum of the highest valid bid (bid >= base price) for each auction.## sample

2
3
100 5 130 150 120 140 150
80 3 100 90 80
50 4 55 60 50 65
2
200 2 250 300
100 3 110 110 110
0
315

410

</p>