Skip to content

Commit

Permalink
Merge pull request #26 from AlgoLeadMe/6-wnsmir
Browse files Browse the repository at this point in the history
6-wnsmir
  • Loading branch information
wnsmir authored Nov 24, 2024
2 parents ba3f103 + f1c4e3b commit 262ad54
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
def flatten_land(N, M, B, land):
min_time = float('inf')
best_height = 0

# ๊ฐ€๋Šฅํ•œ ๋†’์ด h๋ฅผ 0์—์„œ 256๊นŒ์ง€ ์ˆœํšŒ
for h in range(257):
remove_blocks = 0
add_blocks = 0

# ๊ฐ ์ขŒํ‘œ์˜ ๋†’์ด์— ๋Œ€ํ•ด ๋ธ”๋ก ์ œ๊ฑฐ ๋˜๋Š” ์ถ”๊ฐ€ ๊ณ„์‚ฐ
for i in range(N):
for j in range(M):
height_diff = land[i][j] - h
if height_diff > 0:
remove_blocks += height_diff
elif height_diff < 0:
add_blocks -= height_diff

# ์ธ๋ฒคํ† ๋ฆฌ ๋ธ”๋ก๊ณผ ๋น„๊ต
if remove_blocks + B >= add_blocks:
time = remove_blocks * 2 + add_blocks
# ์ตœ์†Œ ์‹œ๊ฐ„ ๊ฐฑ์‹  ๋ฐ ์ตœ๋Œ€ ๋†’์ด ์„ ํƒ
if time < min_time or (time == min_time and h > best_height):
min_time = time
best_height = h

return min_time, best_height
# ์ž…๋ ฅ ์ฒ˜๋ฆฌ
N, M, B = map(int, input().split())
land = [list(map(int, input().split())) for _ in range(N)]
# ๊ฒฐ๊ณผ ๊ณ„์‚ฐ ๋ฐ ์ถœ๋ ฅ
time, height = flatten_land(N, M, B, land)
print(time, height)

0 comments on commit 262ad54

Please sign in to comment.