POSTAL - Editorial

PROBLEM LINKS

Practice
Contest

DIFFICULTY

MEDIUM

EXPLANATION

Notice the following 2 observations

  1. The postmen can be considered as if they are passing through each other
  2. The relative position of a postman never changes

Using the first we can calculate the final positions by just adding or subtracting the time from the initial positions depending on the direction being South or North. Combining this with 2, we can easily see that if we sort the final positions, we will get the position of the the respective postman. But we also have to calculate the collisions. For that we can do the sorting of the positions using Bubble Sort where each swapping of adjacent numbers in the array means a collision. And, hence we can easily count the same.

SETTER’S SOLUTION

Can be found here.

TESTER’S SOLUTION

Can be found here.

//