#C920. Maximum Height Difference Among Collections
Maximum Height Difference Among Collections
Maximum Height Difference Among Collections
You are given a number of collections of plant heights. Each collection contains the heights of several plants. Given an integer k, your task is to compute the maximum height difference among all collections that have at least k plants.
The height difference for a collection is defined as:
[ \text{difference} = \max(\text{collection}) - \min(\text{collection}) ]
If no collection contains at least k plants, output -1
.
Note: Read input from standard input and write output to standard output.
inputFormat
The first line contains two integers n
and k
, where n
is the number of collections, and k
is the minimum number of plants required in a collection.
Each of the following n
lines begins with an integer m
(the number of plants in the collection) followed by m
integers representing the heights of the plants.
For example:
3 3 3 3 6 9 2 1 4 4 10 20 30 40
outputFormat
Output a single integer representing the maximum height difference among all collections with at least k
plants. If no such collection exists, output -1
.
3 3
3 3 6 9
2 1 4
4 10 20 30 40
30