Rook Attack
Practice
4.2 (5 votes)
C++
Basic programming
Problem
69% Success 2181 Attempts 20 Points 1.5s Time Limit 256MB Memory 1024 KB Max Code
Given a \(N \times M\) chessboard, where every cell has a value assigned to it denoted by \(A[i][j]\) (Cell in the \(i^{th}\) row from top and \(j^{th}\) column from left).
Find the position \((x,y)\) where we should place the rook, just the sum of cells which are under attack of rook is maximum possible. The rook can not attack the cell on which it is placed.
If there are more than one positions for \((x,y)\), return the position where \(x\) is as minimum as possible. If there are more than one positions with equal \(x\), return the position where \(y\) is as minimum as possible.
Note:
- \(1\) based indexing is followed.
- A rook can attack all the cells which are either in horizontal or vertical direction to the rook's position.
Input
- First line contains two space separated integers denoting \(N\) and \(M\).
- Next \(N\) lines contains \(M\) space separated integers denoting the values of array \(A\).
Output
Print two space separated integers \(x \ \ y\) denoting the rook's position.
Constrains
\(1 \le N \times M \le 10^6 \\ 1 \le A[i][j] \le 10^4\)
Submissions
Please login to view your submissions
Similar Problems
Points:20
13 votes
Tags:
Basic Programming
Points:20
7 votes
Tags:
Basic ProgrammingBasics of ImplementationEasyHash MapsImplementationString Manipulation
Points:20
94 votes
Tags:
MathematicsOpenApprovedEasy
Editorial