#K78982. Minimum Vendors to Collect All Items
Minimum Vendors to Collect All Items
Minimum Vendors to Collect All Items
You are given a set of vendors selling various items. Each vendor is described by their position on a line and the list of items they sell. The input includes the number of vendors (n) and the total number of distinct items (k). Each vendor's information is given on a separate line: the first number denotes the vendor's position, the second number is the count of items that vendor sells, followed by the list of items. Your task is to choose the minimum number of vendors such that the union of the items they offer covers all (k) items (with item types labeled from 1 to (k)). In case multiple combinations exist, the one with the minimal travel distance (i.e. the difference between the maximum and minimum vendor positions) should be preferred; however, you only need to output the minimum number of vendors required.
Note: It is guaranteed that it is always possible to collect all (k) items.
inputFormat
The first line contains two integers (n) and (k) separated by a space, where (n) is the number of vendors and (k) is the total number of distinct items. The following (n) lines describe each vendor. Each vendor's line consists of integers: the first integer is the vendor's position, the second integer is the number of items sold by that vendor, followed by that many integers representing the item types.
outputFormat
Output a single integer: the minimum number of vendors needed to collect all (k) items.## sample
5 3
2 2 1 2
6 1 1
10 1 3
14 1 2
18 2 2 3
2