求改错ybt1927

怎么改都不会
http://ybt.ssoier.cn:8088/problem_show.php?pid=1927
一本通1927采摘花生
本弱J写的代码:

#include <bits/stdc++.h>

int n, m, k, t = 0, res = 0, nx, ny;
bool first = true;
struct Node
{
    int x, y;
    int value;
};
struct Compare
{
    bool operator()(const Node &a, const Node &b) const
    {
        return a.value < b.value;
    }
};
std::priority_queue<Node, std::vector<Node>, Compare> peanut;

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    scanf("%d%d%d", &n, &m, &k);
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
        {
            int tree;
            scanf("%d", &tree);
            if (tree)
                peanut.push({i, j, tree});
        }
    while (!peanut.empty())
    {
        Node tmp;
        if (first)
        {
            first = false;
            tmp = peanut.top();
            peanut.pop();
            if (tmp.x * 2 + 1 > k)
            {
                printf("0");
                return 0;
            }
            t += tmp.x + 1;
            res += tmp.value;
            nx = tmp.x;
            ny = tmp.y;
            continue;
        }
        tmp = peanut.top();
        peanut.pop();
        if (abs(nx - tmp.x) + abs(ny - tmp.y) + 1 + t + tmp.x > k)
        {
            printf("%d", res);
            return 0;
        }
        t += abs(nx - tmp.x) + abs(ny - tmp.y) + 1;
        nx = tmp.x, ny = tmp.y;
        res += tmp.value;
    }
}
错两个点。。。。。。
人都改傻了
好心人救救孩子吧

根据代码的逻辑来看,可能存在一些问题:

  1. 摘取花生的时间计算有误:在计算每次摘取花生的时间时,使用了abs(nx - tmp.x) + abs(ny - tmp.y) + 1 + t + tmp.x,但实际应该是abs(nx - tmp.x) + abs(ny - tmp.y) + 1 + t,不需要再加上tmp.x
  2. 第一次取出花生树时,判断是否符合时间限制的逻辑有误:应该是判断tmp.x + 1 > k,而不是tmp.x * 2 + 1 > k