can anyone help me out. Its working for all test cases still getting wrong answer.
2 approaches
http://www.codechef.com/viewsolution/6464869
http://www.codechef.com/viewsolution/6464697
In O(N) solution take A = {4,3,5,1,9}.
You will get wrong answer.
My Answer :
Sort the array.
print the first element , n den swap the next two
So, if input is,
5 4 3 2 1
it will sort: 1 2 3 4 5
n output will b like
1 3 2 5 4
Whats wrong in this?
as you have said
“A now becomes = [1, 3, 4, 5].
Our array B will be [1, 5, 3, 4].”
but the solution of A = [1, 3, 4, 5] can also be [ 1 , 4 ,3 ,5] . This is also satisfying your condition. isn’t it ???
@Shashwat.delhi, The approach is already explained in the editorial 
@invest123 You must take into account the separate test cases. you are printing for only one test case!
Thnx. OMG what a mistake
Dint notice that. I think i should use ideone to avoid these mistakes.
what is condition to test cases
He did not pass with this solution. I have updated the new solution.
Your solution is correct, but you are answering for a single test case only. You are not even reading number of test cases.
I am not sure what the error was but the error was probably in map(int,s.split(" ")) , when I replaced it with [int(x) for x in s.split()] it worked .
Here is your corrected code .
http://www.codechef.com/viewsolution/3925500
You are declaring the array in while (testcase --) loop, which is not correct. Number of test cases could be very huge, If you keep allocating so much memory for so many loops, you will get TLE. Ideally you should use vector or you should declare the array globally.
your sorting step is O(N 2 ). You need faster algorithms for sorting. Eg quicksort, mergesort etc. Btw you can use simply STL function sort.
PLEASE CORRECT THE EDITORIAL TO
A[i] >= A[i + 1] if i is odd.
A[i] <= A[i + 1] if i is even.
Hello guys! I’m new to the platform.
How do I read the input using Pythong.
Thanks!
For a single integer you could use:
T = int(input())
And to get a set of whitespace-separated items into a list
items = input().split()
or if you want them as a list of integers:
values = list( map(int, input().split()) )
This is my solution, similar to approach 1, but slightly different. I am not sure why or where it is going wrong…
for i in range((int(input()))):
m = int(input())
n = list(map(int, input().split()))
n.sort()
if m >= 3:
for j in range(1, m-2, 2):
n[j], n[j+1] = n[j+1], n[j]
print(n)