ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 1330. Intervals

WHY WRONG ANSWER ON 17 TEST??????????????HELP ME!
Posted by Master of C++ 22 Mar 2007 22:03
#include <iostream.h>
int main()
{
int mas[10000],x,k=0,p,sum=0,a[5000];
unsigned long int i,j,Q,N;
cin>>N;
for(p=1;p<=N;p++)
{
cin>>a[p];
}
cin>>Q;
for(x=1;x<=Q;x++)
{
sum=0;
cin>>i>>j;
for(p=i;p<=j;p++)
{
sum+=a[p];
}
mas[k]=sum;
k++;
}
for(p=0;p<Q;p++)
cout<<mas[p]<<endl;
return 0;
}
Re: WHY WRONG ANSWER ON 17 TEST??????????????HELP ME!
Posted by Romko [Lviv NU] 23 Mar 2007 00:24
Use DP.
Re: WHY WRONG ANSWER ON 17 TEST??????????????HELP ME!
Posted by CHIDEMYAN SERGEY 23 Mar 2007 17:12
DEAR MASTER OF C++!!!DON'T COUNT SUM!!!INSTEAD OF COUNT SUM USE: a[k]=a[k]+a[k-1];
AND AT ANOTHER CYCLE
for(x=1;x<=Q;x++)
USE b[k]=a[j]-a[i-1];
cout<<b[k]<<endl;
DON'T USE SUM!
GOOD LUCK!!!!!