|
- #include<iostream>
- #include<algorithm>
- #include<cmath>
- using namespace std;
- struct aaa{int rrr,ccc,ss;}q[410];
- int s[25][25];
- int m,n,k,t,cc,ans,r,c,tt,c1,i,j;
- bool mycomp(aaa x,aaa y)
- {
- return x.ss>y.ss;
- }
- int main()
- {
- cin>>m>>n>>k;
- for(i=1;i<=m;i++)
- for(j=1;j<=n;j++)
- {
- cin>>s[i][j];
- if(s[i][j]!=0)
- {
- q[cc].ss=s[i][j];
- q[cc].rrr=i;q[cc].ccc=j;
- cc++;
- }
- }
- t=k;sort(q,q+cc,mycomp);
- //for(i=0;i<cc;i++) cout<<q[i].rrr<<" "<<q[i].ccc<<" "<<q[i].ss<<endl;
- if(q[0].rrr*2+1>t) ans=0;
- else
- {
- ans+=q[0].ss;
- t=t-q[0].rrr-1;tt=abs(q[1].rrr-q[0].rrr)+abs(q[1].ccc-q[0].ccc)+1;c1=1;
- while(tt+q[c1].rrr<=t&&c1<cc)
- {
- ans+=q[c1].ss;t-=tt;c1++;
- tt=abs(q[c1].rrr-q[c1-1].rrr)+abs(q[c1].ccc-q[c1-1].ccc)+1;
- ///cout<<c1<<" "<<ans<<" "<<t<<endl;
- }
- }
- cout<<ans;
- return 0;
- }
复制代码 |
|