포럼
문제 ICPC00246

E. Emptying the Baltic

설명

Gunnar dislikes forces of nature and always comes up with innovative plans to decrease their influence over him. Even though his previous plan of a giant dome over Stockholm to protect from too much sunlight (as well as rain and snow) has not yet been realized, he is now focusing on preempting the possible effects climate change might have on the Baltic Sea, by the elegant solution of simply removing the Baltic from the equation.

First, Gunnar wants to build a floodbank connecting Denmark and Norway to separate the Baltic from the Atlantic Ocean. The floodbank will also help protect Nordic countries from rising sea levels in the ocean. Next, Gunnar installs a device that can drain the Baltic from the seafloor. The device will drain as much water as needed to the Earth's core where it will disappear forever (because that is how physics works, at least as far as Gunnar is concerned). However, depending on the placement of the device, the entire Baltic might not be completely drained – some pockets of water may remain.

To simplify the problem, Gunnar is approximating the map of the Baltic using a \(2\)-dimensional grid with \(1\) meter squares. For each square on the grid, he computes the average altitude. Squares with negative altitude are covered by water, squares with non-negative altitude are dry. Altitude is given in meters above the sea level, so the sea level has altitude of exactly \(0\). He disregards lakes and dry land below the sea level, as these would not change the estimate much anyway.

Water from a square on the grid can flow to any of its \(8\) neighbours, even if the two squares only share a corner. The map is surrounded by dry land, so water never flows outside of the map. Water respects gravity, so it can only flow closer to the Earth's core – either via the drainage device or to a neighbouring square with a lower water level.

Gunnar is more of an idea person than a programmer, so he has asked for your help to evaluate how much water would be drained for a given placement of the device.

제약
입력 형식

The first line contains two integers \(h\) and \(w\), \(1 \leq h, w \leq 500\), denoting the height and width of the map.

Then follow \(h\) lines, each containing \(w\) integers. The first line represents the northernmost row of Gunnar's map. Each integer represents the altitude of a square on the map grid. The altitude is given in meters and it is at least \(-10^6\) and at most \(10^6\).

The last line contains two integers \(i\) and \(j\), $1 \leq i \leq h,
1 \leq j \leq w\(, indicating\ that\ the\ draining\ device\ is\ placed\ in\ the\ cell\ corresponding\ to\ the \)j\('th\ column\ of\ the \)i\('th\ row. You\ may\ assume\ that\ position \)(i, j)$ has negative altitude (i.e., the draining device is not placed on land).

출력 형식

Output one line with one integer – the total volume of sea water drained, in cubic meters.

예제 1
입력
3 3
-5 2 -5
-1 -2 -1
5 4 -5
2 2
출력
10
예제 2
입력
2 3
-2 -3 -4
-3 -2 -3
2 1
출력
16
문제 정보

생성자가 기록되지 않았습니다.

출처 ICPC NCPC 2017

평가 및 의견

E. Emptying the Baltic

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 1 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

E. Emptying the Baltic

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8