#jag2017summerday3g. [jag2017summer_day3_g]Low Range-Sum Matrix
[jag2017summer_day3_g]Low Range-Sum Matrix
MathJax.Hub.Config({ tex2jax: { inlineMath: [[""], ["\\(","\\)"]], processEscapes: true }}); blockquote { font-family: Menlo, Monaco, "Courier New", monospace; color: #333333; display: block; padding: 8.5px; margin: 0 0 9px; font-size: 16px; line-height: 18px; background-color: #f5f5f5; border: 1px solid #ccc; border: 1px solid rgba(0, 0, 0, 0.15); -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; white-space: pre; white-space: pre-wrap; word-break: break-all; word-wrap: break-word; }
Problem Statement
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.
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
.
Sample Input 1
3 3 2 10
5 3 7
2 6 1
3 4 1
Output for Sample Input 1
Yes
The sum of a horizontal contiguous subsequence from to is . The sum of a vertical contiguous subsequence from to is . If you flip the sign of , there is no vertical or horizontal contiguous subsequence whose sum is greater than .
Sample Input 2
2 3 1 5
4 8 -2
-2 -5 -3
Output for Sample Input 2
Yes
Sample Input 3
2 3 1 5
9 8 -2
-2 -5 -3
Output for Sample Input 3
No
Sample Input 4
2 2 3 100
0 0
0 0
Output for Sample Input 4
Yes