I am not able to locate any error in approach.
include
include
using namespace std;
int main()
{
int t;
long long int i,sum,k,n,max,sumuptomax=0,l[100000]={0},minans=1000000000,temp,tempans,sumaftermax=0;
scanf("%d",&t);
while(t--)
{
sum=0;max=0;temp=0;tempans=100000000;
sumuptomax=0;
sumaftermax=0;
minans=1000000000;
scanf("%lld",&n);
i=0;
while(n--)
{
scanf("%lld",&l[i]);
if(l[i]>max)
{
max=l[i];
}
sum+=l[i];
i++;
}
for(int j=0;j{
if(l[j]==max)
{
sumuptomax=temp;
sumaftermax=sum-temp-max;
if(sumuptomax>sumaftermax)
tempans=2*sumaftermax+sumuptomax;
else
tempans=2*sumuptomax+sumaftermax;
if(tempansminans=tempans;
}
temp+=l[j];
}
printf("%lld\n",minans);
}
return 0;
}