Bingo
Time limit1sMemory limit512 MB
Place one token in each column of an N x M matrix, minimizing first the spread of token counts across rows, then the largest token value.
- Level
Medium7 of 10
- Topics
- Greedy, Binary search, Sorting, Implementation
- Solved
- No attempts yet
Problem
Consider the following game. You have an integer matrix of size . Your task is to place tokens on cells of the matrix such that:
- each column contains exactly one token;
- the difference between the maximum and minimum number of tokens in a row is as small as possible;
- among all such placements, you choose one where the maximum value written in a cell that holds a token is as small as possible.
Input
The first line contains two integers and (). Then the matrix follows: lines, each containing integers ().
Output
Print two integers that describe the placement you found: the minimum possible value of and the minimum value written in a cell that holds a token, separated by a space.