Low Range-Sum Matrix
Time limit2sMemory limit512 MB
Flip signs of at most K cells in an N by M matrix (both at most 10) so that no horizontal or vertical contiguous segment sums to more than S.
- Level
Hard9 of 10
- Topics
- Brute force, Dynamic programming, Bit manipulation, Implementation
- Solved
- No attempts yet
Problem
You received a card at a banquet. On the card, a matrix of rows and columns and two integers and are written. All the elements in the matrix are integers, and an integer at the -th row from the top and the -th column from the left is denoted by .
You can select up to elements from the matrix and invert the sign of the elements. If you can make a matrix such that there is no vertical or horizontal contiguous subsequence whose sum is greater than , you can exchange your card for a prize.
Your task is to determine if you can exchange a given card for a prize.
Input
The input consists of a single test case of the following form.
$N$ $M$ $K$ $S$
$A_{1,1}$ $A_{1,2}$ $\cdots$ $A_{1,M}$
$\vdots$
$A_{N,1}$ $A_{N,2}$ $\cdots$ $A_{N,M}$
The first line consists of four integers , , , and (, , ). The following lines represent the matrix in your card. The -th line consists of integers , , , ().
Output
If you can exchange your card for a prize, print Yes. Otherwise, print No.