Can some one please explain the solution for this problem ? Also ,please give some advice for solving Constructive Algorithms questions ?
https://codeforces.com/contest/347/problem/A
Thanks in advance
Can some one please explain the solution for this problem ? Also ,please give some advice for solving Constructive Algorithms questions ?
https://codeforces.com/contest/347/problem/A
Thanks in advance
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 , btw do you know how to master in solving Constructive algo problems ?
solve a2oj ladder codeforces problems.
n=int(input())
x=sorted([int(x) for x in input().split()])
x[0],x[-1]=x[-1],x[0]
print(*x)
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
Hackerrank also have a Constructive Algorithms section to practise on
Thanks bro