90分求助#5WA了,求助神犇!!!!
查看原帖
90分求助#5WA了,求助神犇!!!!
1061881
SQRW楼主2024/3/23 13:47
#include<bits/stdc++.h>
using namespace std;
struct node{
    int t;
    int x;
    int y;
    int s;
    }s[403];
int a[24][25];
bool cmp(node b,node c){
	return b.t>c.t;
}int n,m,x,c;
int main(){
long long sum=0;
	cin>>n>>m>>x;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>a[i][j];
			if(a[i][j]){
                s[++c].x=i;
                s[c].y=j;
                s[c].t=a[i][j];
			};
		}
	}
	sort(s+1,s+1+c,cmp);
	s[1].s=s[1].x;
	if(x>=s[1].s*2){
            sum=s[1].t;
    x-=s[1].s;}
	else {
        cout<<0;
        return 0;
	}
	for(int i=2;i<=c;i++){
        s[i].s=abs(s[i].x-s[i-1].x)+abs(s[i].y-s[i-1].y)+1;
        x-=s[i].s;
        if(x>s[i].x)sum+=s[i].t;
        else break;
	}
	cout<<sum;
	return 0;
}

2024/3/23 13:47
加载中...