Most likely, you will notice that you have a mouse attached to your computer, which lets you move the cursor around the screen. Your job is to get between the mouse and the cursor.
Suppose that the bottom left-hand corner of your screen is , and all points on the screen are given by integer co-ordinates where and . Thus, the top-right corner of the screen is at position , bottom-right corner is , and top-left corner is .
When a mouse is moved, it sends a pair of integers , indicating that the cursor should be moved units in the x-direction and units in the y-direction. It is worth noting that this is relative motion (i.e., how far to move) rather than absolute motion (i.e., where to move). It is also worth noting that and may be positive, negative or zero.
You can assume the mouse starts at position . Your job is to read input messages (i.e., relative motion positions sent by the mouse) and update the cursor to the new position on the screen. Your output (to the screen) will be the position of the mouse after each move.
If the mouse hits the screen boundary, it stops moving in that direction. For example, if the mouse is supposed to move from its current position , the final positions will be : the mouse will hit the left-hand side boundary, but still manages to move down.
Input is listed as pairs, the first pair being , followed by the relative motion pairs . The input is terminated when the mouse moves .
Sample Input 1
100 200 10 40 -5 15 30 -30 0 0
Sample Output 1
10 40 5 55 35 25
Sample Input 2
30 40 30 40 -100 -10 0 0
Sample Output 2
30 40 0 30
CCC problem statements in large part from the PEG OJ