#K74042. Taco Problem Selection
Taco Problem Selection
Taco Problem Selection
You are given a list of problems. Each problem is represented by three values: an integer problem ID, a string representing its category, and an integer difficulty level. You are also given a set of difficulty levels and an integer per_category_count. Your task is to select problems whose difficulty is in the given set while ensuring that, for each category, you select at most per_category_count problems. After processing the list in input order, output the selected problem IDs in ascending order. Formally, let (P = [(id_i, cat_i, diff_i)]) be the list of problems, and let (D) be the set of acceptable difficulties. For each problem, if (diff_i \in D) and the number of previously selected problems from category (cat_i) is less than (per_category_count), then select (id_i). Finally, sort the selected problem IDs. This problem tests your skills in simulation and greedy selection.
inputFormat
The input is read from standard input (stdin) and has the following format:\
- The first line contains an integer (n), the number of problems.\
- Each of the next (n) lines contains three values separated by spaces: an integer problem ID, a string category (without spaces), and an integer difficulty.\
- The next line contains an integer (k), the number of acceptable difficulty levels.\
- The following line contains (k) space-separated integers denoting the acceptable difficulty levels.\
- The last line contains an integer (per_category_count), the maximum number of problems that can be selected from each category.
outputFormat
Output a single line to standard output (stdout) containing the selected problem IDs in ascending order, separated by spaces. If no problems are selected, output an empty line.## sample
6
1 Algorithms 3
2 Algorithms 2
3 Data_Structures 3
4 Data_Structures 4
5 General_Knowledge 2
6 General_Knowledge 3
2
2 3
2
1 2 3 5 6