Codeforces - problem doubt

Can some one please explain the solution for this problem ? Also ,please give some advice for solving Constructive Algorithms questions ?

Thanks in advance :slight_smile:

Bro its basic maths.In an arrangement answer would be x(1) - x(n).
So, just take x(1) a maximum element and x(n) as minimum element,and sort the other elements of array.Basically just sort the array and swap first element with the last.


Thanks :slight_smile: , btw do you know how to master in solving Constructive algo problems ?

solve a2oj ladder codeforces problems.

x=sorted([int(x) for x in input().split()])

short code hope this works


i am not skilled enough to answer that.

As with Greedy algorithms, there’s always a bunch of observation, creativity, ingenuity and raw problem-solving required, but in this case one strategy if you’re completely stuck as to how an optimal solution is constructed (and it’s a strategy I always advocate regardless of the Problem type :)) is to write a simple brute-force solution and a randomised testcase generator and see if you can spot some patterns in the answers the brute-force solution comes up with. In this case, a brute-force solution will be about O(N\times N!) so we’ll start running into trouble at about N=10, but I’m betting a clear pattern would emerge after a few testcases regardless :slight_smile:

Hackerrank also have a Constructive Algorithms section to practise on :slight_smile:


Thanks bro :slight_smile:

1 Like