#C7213. Robot Energy Navigation

    ID: 51060 Type: Default 1000ms 256MiB

Robot Energy Navigation

Robot Energy Navigation

Problem Description

You are given an N × N grid where each cell contains an integer representing the energy cost to enter that cell. A robot starts at the top-left corner (cell (0, 0)) and needs to reach the bottom-right corner (cell (N-1, N-1)). The robot can only move either to the right or down at each step. Given the robot's initial energy E, your task is to determine if it is possible for the robot to reach the destination, such that the total energy cost is less than or equal to E.

Formally, let \( grid[i][j] \) be the energy cost at cell \( (i,j) \). The cost of a path is the sum of the energy costs of all visited cells. You need to decide whether the minimum possible path cost from the top-left to the bottom-right is \( \le E \). All energy costs and E are non-negative integers.

Note: The optimal path is the one with the minimum sum of energy costs, and the robot can only move right or down.

inputFormat

The first line of the input contains an integer T (the number of test cases). Each test case is described as follows:

  • The first line of each test case contains two integers N and E, where N is the size of the grid and E is the initial energy of the robot.
  • This is followed by N lines, each containing N space-separated integers representing the energy cost grid.

It is guaranteed that all values are non-negative integers.

outputFormat

For each test case, output a single line containing either "Yes" or "No". Output "Yes" if the robot is able to reach the destination (bottom-right cell) with the given energy E, otherwise output "No".

## sample
3
3 15
1 3 6
2 0 2
4 4 0
2 3
1 5
2 1
2 10
1 5
2 1
Yes

No Yes

</p>