#C1898. Taco Delivery Challenge

    ID: 45153 Type: Default 1000ms 256MiB

Taco Delivery Challenge

Taco Delivery Challenge

You are given a grid representing a city with obstacles, delivery points, and charging stations. The grid is composed of the following characters:

  • R: The starting position of the robot.
  • D: A delivery point that the robot must visit.
  • C: A charging station where the robot can recharge its battery to full capacity.
  • #: An obstacle that the robot cannot cross.
  • .: A free cell that the robot can move through.

The robot has a battery with a given capacity. Every move (up, down, left, right) consumes one unit of battery. However, if the robot reaches a charging station (C), it can recharge its battery to full capacity. The robot needs to visit all the delivery points before its battery runs out. If there are no delivery points present, consider the task as completed.

Your task is to determine whether the robot can complete all deliveries given the grid and battery capacity. If it can, print YES, otherwise print NO. All input is provided via standard input (stdin) and the result should be printed to standard output (stdout).

Note: If the robot cannot be found on the grid, print NO.

inputFormat

The first line of input contains two integers n and battery, where n is the number of rows in the grid and battery is the robot's battery capacity.

The following n lines each contain a string representing a row of the grid. All rows have the same length.

outputFormat

Print a single line containing YES if the robot can complete all deliveries, otherwise print NO.

## sample
5 8
R....
..#..
#.D.#
D.#.D
#...C
YES