20250727 baekjoon
This commit is contained in:
parent
98f68a7c7e
commit
a29dfc5042
37
code_study/Baekjoon/python/18111.py
Normal file
37
code_study/Baekjoon/python/18111.py
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
import sys
|
||||||
|
|
||||||
|
input = sys.stdin.readline
|
||||||
|
N, M, B = map(int, input().split())
|
||||||
|
blockList = [0]*257
|
||||||
|
for _ in range(N):
|
||||||
|
for height in map(int, input().split()):
|
||||||
|
blockList[height] += 1
|
||||||
|
|
||||||
|
min_time = float('inf')
|
||||||
|
best_height = -1
|
||||||
|
|
||||||
|
for target_height in range(257):
|
||||||
|
inventory = B
|
||||||
|
time = 0
|
||||||
|
|
||||||
|
for current_height in range(256):
|
||||||
|
if blockList[current_height] == 0 :
|
||||||
|
continue
|
||||||
|
if current_height > target_height:
|
||||||
|
diff = current_height - target_height
|
||||||
|
count = blockList[current_height]
|
||||||
|
inventory += diff*count
|
||||||
|
time += 2*diff*count
|
||||||
|
else:
|
||||||
|
diff = target_height - current_height
|
||||||
|
count = blockList[current_height]
|
||||||
|
inventory -= diff*count
|
||||||
|
time += diff*count
|
||||||
|
|
||||||
|
if inventory >= 0:
|
||||||
|
if time < min_time:
|
||||||
|
min_time = time
|
||||||
|
best_height = target_height
|
||||||
|
|
||||||
|
result = ' '.join([str(min_time), str(best_height)]) + '\n'
|
||||||
|
sys.stdout.write(result)
|
||||||
Loading…
x
Reference in New Issue
Block a user