QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#22768. New Years Party

Statistics

A group of $N$ ($3 \le N \le 200$) cows is having a New Year's party. Each cow is able to cook several different kinds of food (in units called a "dish"). There are a total of $D$ ($5 \le D \le 100$) different kinds of food. Each kind of food is denoted by an integer in the range $1..D$.

The cowrdinator wants to maximize the total number of dishes brought to the party, but has specified a limit for the number of dishes of each type. Each cow can bring $K$ ($1 \le K \le 5$) dishes, but they must be different from each other (she can't bring 3 bovine pies, for example, but she could bring a pie, some bread, and some nice alfalfa in orange sauce). What is the maximum amount of food that can be brought?

Input

  • Line $1$: Three integers: $N$, $K$, and $D$
  • Line $2$: $D$ non-negative integers: the limit on total number of each of the various dishes that can be brought to the party
  • Lines $3..N+2$: Each line contains an initial integer $Z$ ($1 \le Z \le D$) denoting the number of different dishes a cow can prepare; the rest of the line contains $Z$ integers that are the food identifiers, food type 1 first, food type 2 second, etc..

Output

A single line with a single integer that is the maximum number of dishes that can be brought to the party.

Examples

Input 1

4 3 5
2 2 2 2 3
4 1 2 3 4
4 2 3 4 5
3 1 2 4
3 1 2 3

Output 1

9

Input Details

data......     explanation...................................................
4 3 5          4 cows, each cow brings up to 3 dishes, 5 different food types
2 2 2 2 3      max for party of 2 dishes food types 1..4; 3 dishes of food 5
4 1 2 3 4      This cow can cook 4 different foods (1, 2, 3, 4)
4 2 3 4 5      This cow can cook 4 different foods (2, 3, 4, 5)
3 1 2 4        This cow can cook 3 different foods (1, 2, 4)
3 1 2 3        This cow can cook 3 different foods (1, 2, 3)

Output Details

[Cow 1 brings foods 3 and 4; cow 2 brings foods 3, 4 and 5; cow 3 brings foods 1 and 2; and cow 4 brings foods 1 and 2.]

Problem credits: Hal Burch, 2001

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.