#K72202. Waypoint Generation
Waypoint Generation
Waypoint Generation
You are given two integers a and b representing the coordinates of a target point (a, b). Your task is to generate a sequence of waypoints starting from (0, 0) that leads to (a, b) by moving one unit at a time horizontally or vertically. That is, each successive waypoint differs by exactly 1 in either the x‐direction or y‐direction.
A valid path is constructed by first moving in the horizontal direction until the x-coordinate is reached, then moving vertically until the y-coordinate is reached. However, if the Manhattan distance (|a|+|b|) exceeds (10^6), output the string "IMPOSSIBLE" instead.
For example, for input (3, 4), a valid output is:
(0, 0) (1, 0) (2, 0) (3, 0) (3, 1) (3, 2) (3, 3) (3, 4)
Note: The Manhattan distance is defined as (|a| + |b|).
inputFormat
Input is read from standard input. It consists of two space-separated integers a and b on a single line representing the x and y coordinates of the destination.
outputFormat
Output to standard output a single line. If a valid path exists, output the sequence of waypoints starting from (0, 0) to (a, b) separated by a single space. Each waypoint is formatted as (x, y). If the Manhattan distance (|a| + |b|) exceeds (10^6), output the string "IMPOSSIBLE".## sample
3 4
(0, 0) (1, 0) (2, 0) (3, 0) (3, 1) (3, 2) (3, 3) (3, 4)