SIMBABY - Editorial

PROBLEM LINK:

Contest

Author: Shivank Pathak

Editorialist: Shivank Pathak

DIFFICULTY:

EASY

PREREQUISITES:

Math

PROBLEM:

The problem is to calculate the optimal scores and check if the two persons have similar scores.

EXPLANATION:

The order of covering the points is already defined, the problem just reduces to figuring out the way to calculate the scores between 2 points (A, B) and (C, D).

Note that what only matters is X = abs(A-C) and Y = abs(B-D).

While X and Y are positive, you will move along the diagonal and X and Y would both reduce by 1.
When one of them becomes 0, you would move so that in each step the remaining number reduces by 1.

In other words, the total number of steps would correspond to max(X, Y).

Then we have to sort the scores of both and then compare it.

AUTHOR’S AND TESTER’S SOLUTIONS:

Author’s solution can be found here.