1 / 5
Aug 2016

include

using namespace std;

int main()
{

unsigned int N,i,j,k,q,sum,A,B;
cin>>N;
int x[N+1];
for(i=1;i<=N;i++)
{
	cin>>x[i];

}
cin>>q;
int b[q][2];
for(j=0;j<q;j++)
{
	for(k=0;k<2;k++)
	cin>>b[j][k];
}

	for(j=0;j<q;j++)
	{
		sum=0;
		A=b[j][0];
		B=b[j][1];
		for(i=A;i<=B;i++)
		{
			sum+=x[i];
		}
		cout<<sum<<endl;
	}

}
how do i remove tle for this program

  • created

    Aug '16
  • last reply

    Jul '17
  • 4

    replies

  • 1.1k

    views

  • 3

    users

  • 1

    link

Welcome to SPOJ. Please provide a link to the problem you are dealing with – or at least the problem code.

For problems like this it can help to think mathematical: use the integral and subtract integral value of upper and lower bound. Your approach is “brute force” and possibly sums up the same numbers again and again

11 months later

My program is running on ideon but on submission it shows runtime error (SIGSEGV).

include
int main(void)
{
int t,c,i,a[80];
t=5;
for(i=0;i<t;i++)
{
scanf("%d",&c);
a[i]=c;
}
i=0;
while(a[i]!=42)
{
printf("%d\n",a[i]);
i++;
}
}

Suggested Topics

Topic Category Replies Views Activity
C and C++ 0 43 Jun 29

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