#include <bits/stdc++.h>
using namespace std;
struct tnut{
int x,y,price;
}a[404];
bool cmp(tnut x,tnut y){
return x.price>y.price;
}
int main(){
int n,m,k,cnt=0;
cin>>n>>m>>k;
int tmp;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>tmp;
if(tmp>0){
a[cnt].x=i;
a[cnt].y=j;
a[cnt].price=tmp;
cnt++;
}
}
}
sort(a,a+cnt,cmp);
//for(int i=0;i<cnt;i++)cout<<a[i].x<<" "<<a[i].y<<" "<<a[i].price<<" "<<endl;
//cout<<endl;
k--;
int ans=0;
for(int i=0;i<cnt;i++){
int len=0,len2=0;
if(i==0){len=a[i].x+1;len2=a[i].x;}
else {
len+=abs(a[i].x-a[i-1].x);
len+=abs(a[i].y-a[i-1].y)+1;
len2=a[i].y+1;
//len+=len2;
}
if(k-len-len2>0){
k-=len;ans+=a[i].price;
//cout<<i<<" "<<a[i].x<<" "<<a[i].y<<" "<<a[i].price<<" "<<k<<" "<<ans<<endl;
}
else {
cout<<ans<<endl;
return 0;
}
}
cout<<ans<<endl;
return 0;
}
为什么7和10会不过啊