Increasing Decreasing ( Unofficial Editorial , Ltime 85 )

Hey, I tried the same approach as you mentioned Above. but My code was giving WA in first subtask and TLE in second subtask . Kindly check my code and tell the mistake or any test case for which the code fails.
Thanks
https://www.codechef.com/viewsolution/34807952

Here is my solution with a very similar approach to yours… will you please check where did i go wrong…
https://www.codechef.com/viewsolution/34825450

Any help would be highly appreciated.