题目描述
python 堆
样例
r,c,l=map(int,input().split())
heap=[]
for i in range(r):
grid=list(map(int,input().split()))
for j in range(c):
if grid[j]>0:
heap.append((-grid[j],i+1,j))
import heapq
heapq.heapify(heap)
res=0
cy=0
cx=heap[0][2]
while heap:
v,y,x=heapq.heappop(heap)
if abs(y-cy)+abs(x-cx)+y<l:
res+=(-v)
l-=(abs(y-cy)+abs(x-cx)+1)
cy=y
cx=x
else:
break
print(res)