eolymp
bolt
Try our new interface for solving problems
Problems

Pareto domination

Pareto domination

A point with coordinates (\textbf{x1}, \textbf{x2}, …, \textbf{xn}) is called dominated in Pareto’s sense by a point with coordinates (\textbf{y1}, \textbf{y2}, …, \textbf{yn}), if for each \textbf{i} (\textbf{1} ≤ \textbf{i} ≤ \textbf{n}) the inequality \textbf{xi} ≤ \textbf{yi }holds. A set of some points is given. Your task is to find the number of points in this set, that are not dominated in Pareto’s sense by any other point in the given set. \InputFile First line of input contains the quantity of tests \textbf{T} (\textbf{1} ≤ \textbf{T} ≤ \textbf{10}). First line of each test case contains two numbers: \textbf{N} (\textbf{1} ≤ \textbf{N} ≤ \textbf{50000}) -- the number of points in the set and \textbf{M} (\textbf{1} ≤ \textbf{M} ≤ \textbf{4}) -- the space dimension. Then there are \textbf{N} lines, each of which contains \textbf{M} integers -- coordinates of a point, separated by spaces (each coordinate is less than \textbf{10^9} by its absolute value). All points in the set are different. \OutputFile Output \textbf{T} lines of the form "\textbf{Case} #\textbf{A}: \textbf{B}", where \textbf{A} is the number of test (beginning from 1), \textbf{B} is the quantity of non-dominated points.
Time limit 10 seconds
Memory limit 64 MiB
Input example #1
2
4 1
1
2
3
4
4 2
0 0
1 1
2 0
0 2
Output example #1
Case #1: 1
Case #2: 3