1 / 2
Jan 2012

#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.

  • created

    Jan '12
  • last reply

    Jan '12
  • 1

    reply

  • 125

    views

  • 2

    users

Suggested Topics

Topic Category Replies Views Activity
C and C++ 0 18 11d

Want to read more? Browse other topics in C and C++ or view latest topics.