# I am getting wrong answer in CHEFSUM

Hello, everyone am a newbie to codechef. So I am getting wrong answer in sept17 chefsum problem can anyone explain to me what’s “missing” or “wrong” in my code? It would be of great help.

My solution: Solution

1 Like

There are a few mistakes in your code. Take a look at the editorial, it should be able to help you. If you still face problems, let us know.

Okay, thanks…

you will get tle since you are finding it everytime .
The question says u need to find the least(prefix sum+suffix sum) for n elements. So the common observation is if you do prefix+suffix , that will always remain equal to the total sum +the element at which you are doing that , so in order to find the least pre+suff , you can only find the minimum element in the array and display index+1.(there are many other waist do it.) There is the solution link below.

Which searching algorithm would be wise to use here and why?

For searching the minimum number , the only the thing you need to do is take the input of numbers of the array and keep on checking if it is lower than the previous lowest . If yes , update the minimum number variable and store the index or the counter at the time of that number input . Remember that this is 1 indexed .
You can have a look at my solution : https://www.codechef.com/viewsolution/15200583

Thanks a lot…

Hi @trashmaster m still getting wrong answer can you plz give a look at my solution.

PS: I have updated my solution

1. In easier words, you have to find the index for (first) minimum element (in case of multiple minimum elements).

Your implementation is wrong. Once you find total sum of array, the prefix sum is \sum Arr[i] while suffix sum is Totsum-\sum Arr[i-1] (since element at i is considered twice). You did not implement this and have done something else.

(1) First of all write test-- only in the while condition , nothing more to check

(2) No need to check for the constraints on num . It will never be violated .

(3) There is no need to store the numbers just check and take the input using a single variable only .

(4) Thre is no need to take the total sum .

(5) You just need to find the minimum element and its index by successively taking input .

1 Like

Thanks a lot…

If you are satisfied with my answer , may be you can accept it . May be .

SORRY as I said am new… nyway thx for ur precious tym…