Suppose I am taking n=5 and k=2, according to the explanation of this question posted on codechef’s YouTube channel the answer is
1 -2 3 -4 -5 .
I want to know why 1 2 -3 -4 -5 is not the answer of the question?
the positive prefixes would be 1 3 0 -4 -9, and i think zero is where the problem lies.
but we cannot have 0 and those numbers which are greater than n (which is 5 in my case).
basically what they told in the editorial is to take the alternate positions as -ve . like 1 -2 3 -4 5 and so on, and my question is why its giving me WA when i am taking +ve integers one after the other and the number of +ve integers is also equal to k, for instance 1 2 -3 -4 -5 taking n=5 and k=2.
just explain me the approach, rest i’ll do myself. Thanks
Suppose n=6 and k=5
U would choose 1 2 3 4 5 -6
But that’s wrong
I agree that from number 1 to 5 the sum is +ve i.e (1+2+3+4+5) and k is 5 but when u reach -6 ,the sum is (1+2+3+4+5-6), since this is also +ve u have computed for k=6 not 5.
got your point, thats why they were taking alternating +ve ,-ve integers. Thanks
There are many answers and you can print any one of them. You answer is correct in my opinion, how do you know the grader is saying that answer is not correct? My answer for the case N=5 and K=2 was 1 -2 -3 4 5, which was marked as correct, the sums are 1, -1, -4, 0 and 5, so I think a zero sum does not count towards K.
nope, my answer gave me WA, i tried it twice and it gave me WA both time.
Yes because your algorithm is wrong not because of its answer to N=5, k=2. if you put N=5 and K=3 into your solution you get 1,2,3,-4,-5 and the sums are 1,3,6,2,-3 so K=4, hence WA.
Yeah I understood where I was wrong