#include<iostream>
using namespace std;
int main()
{
int x,ncor,maxr=-1,maxri,i;
unsigned long long int rs,rd,v[1000001];
cin>>x;
while(x)
{
cin>>ncor;
rs=rd=0;
for(i=1;i<=ncor;i++)
{
cin>>v[i];
if(v[i]>maxr)
{
maxr=v[i];
maxri=i;
}
}
for(i=maxri+1;i<=ncor;i++)
rs+=v[i];
if(maxri!=1)
{
for(i=1;i<maxri;i++)
rd+=v[i];
if(rs*2+rd<maxr || rd*2+rs<maxr)
if(rs<=rd)
cout<<rs*2+rd<<endl;
else cout<<rd*2+rs<<endl;
else cout<<rs+rd+maxr<<endl;
}
else cout<<rs<<endl;
x--;
}
return 0;
}
I don't understand what i'm doing wrong. The code seems to work on every imput i could think of.