# Little Chef and Sums

This is my code:

#include <stdio.h>
#include <stdlib.h>
int ssum (int *arr, int j, int N){
int i;
int total=0;
for(i=0;i<j+1;i++){
total=total+arr[i];
}
}
int lsum (int *arr, int j, int N){
int i;
j++;
int temp=N-j+1;
int total=0;
for(i=0;i<temp;i++){
total=total+arr[N-1-i];
}
}

int findMin(int *res, int N){
int minimum = res[0];
int i;
int var;
for(i=0;i<N;i++){
if(res[i]<minimum){
minimum = res[i];
var = i;
}
}
return var;
}
int main(){
int test;
scanf("%d",&test);
int i,j,k;
int result[test];
for(i=0;i<test;i++){

int N;
scanf("%d",&N);
int arr[N];
int res[N];
int pf[N],sf[N];
for(j=0;j<N;j++){
scanf("%d", &arr[j]);
}
for(j=0;j<N;j++){
pf[j]=ssum(arr,j,N);
sf[j]=lsum(arr,j,N);
res[j]=pf[j]+sf[j];
printf("Prefix Sum[%d]: %d, Suffix Sum[%d]: %d, Total: %d\n",j,pf[j],j,sf[j],pf[j]+sf[j]);
}
result[i] = findMin(res,N);
}
for(i=0;i<test;i++){
printf("Result :%d \n",result[i]+1);
}

}

This runs without any difficulty in CodeBlocks IDE but not on the CodeChef Interpreter. IDK WHy. Help Appreciated

Its a machine checking if what you print is an “exact” match of expected output. Remove those statements like “Result:” etc. Print only whats asked.

Then, total prefix sum can be as large as {10}^{10}, which is out of range of int. So you suffer from overflow as well, giving WA.

On correction, you will get tle due to unrefined calculatiob of prefix sum etc by doing same computations again and again. Try reducing it to single for loop, instead of nested for loops.

//