ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1005. Stone Pile

Where is my mistake?
Posted by Volov_Forever 20 Mar 2009 00:58
WHERE IS MY MISTAKE???

#include <iostream>
#include <cmath>
using namespace std;
int main ()
{
    int a[100000],n,i,s1=0,s2=0,min;
    cin>>n;
    for (i=1;i<=n;i++)
    cin>>a[i];
    for (i=1;i<=n;i++)
    {
        if (s1>s2)  s2+=a[i];
        else if (s1==s2) s1+=a[i];
        else s1+=a[i];
    }
    min=abs (s1-s2);
    cout<<min<<endl;
    return 0;
}
Re: Where is my mistake?
Posted by OpenGL 20 Mar 2009 14:08
Try this test
5
10 10 8 4 8
Right answer is 0

Edited by author 20.03.2009 14:09
Re: Where is my mistake?
Posted by Volov_Forever 20 Mar 2009 22:24
My answer is 4.Why is 0?
Re: Where is my mistake?
Posted by OpenGL 23 Mar 2009 17:54
10+10=8+4+8=20
Re: Where is my mistake?
Posted by Volov_Forever 24 Mar 2009 13:28
Thanks!!!
Re: Where is my mistake?
Posted by aleko 13 May 2009 15:13
my answer is 4 too
Re: Where is my mistake?
Posted by George Skhirtladze 12 Apr 2010 16:34
Hey do you know test #5