Logo
(追記) (追記ここまで)

25040번 - Zemljište 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB114363437.778%

문제

Matej is, as is well known, the biggest Croatian innovator and businessman. His company is expanding, which is why he decided to buy a plot of land near Velika Gorica. The available land is a rectangle-shaped region consisting of $r \times s$ square unit cells. Each cell has its own price and it’s not possible to purchase only a part of a cell. Matej is an experienced businessman and he knows that the key to success is not simply to buy the biggest plot of land or the least expensive one. Instead, he should buy a plot of land whose price is as close as possible to the magic numbers given to him by Milan the psychic.

At the beginning of his career, Milan revealed to Matej two magic numbers $a$ and $b$ crucial for commercial success. Therefore, Matej wishes to buy a (nonempty) rectangular plot of land so that the distance between its price and the magic numbers is as small as possible. The distance between the price and a single magic number is just the absolute value of their difference, and the distance between the price and both of the magic numbers is the sum of these absolute differences. Help Matej and determine the minimum possible distance between the price of the plot of land and the two magic numbers.

입력

The first line contains positive integers $r,ドル $s,ドル $a$ and $b$ (1ドル ≤ r, s ≤ 500,ドル 1ドル ≤ a, b ≤ 10^9$) from the problem.

The $i$-th of the following $r$ lines contains a sequence of s positive integers $c_{ij}$ (1ドル ≤ c_{ij} ≤ 10^9$), the prices of the individual cells, in order.

출력

In the only line print the minimum possible distance between the price of the plot of land and the two magic numbers.

제한

서브태스크

번호배점제한
110

1ドル ≤ r, s ≤ 20$

220

1ドル ≤ r, s ≤ 100$

340

No additional constraints.

예제 입력 1

2 2 10 10
1 3
4 1

예제 출력 1

2

예제 입력 2

3 2 3 4
1 9
1 1
8 1

예제 출력 2

3

예제 입력 3

3 4 5 3
1 1 1 1
9 6 7 6
8 1 9 7

예제 출력 3

2

힌트

Clarification of the second example: Matej can buy a plot of land consisting of two adjacent cells of cost 1ドル$. The total price is then 1ドル + 1 = 2,ドル and the distance between it and the magic numbers is $|3 - 2| + |4 - 2| = 3$.

출처

Contest > Croatian Open Competition in Informatics > COCI 2021/2022 > Contest #6 2번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /