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

ACCEPTED!!!
Posted by Seroj RAU 1 Nov 2010 20:07
#include <iostream>

using namespace std;

int main()
{
    long int a, i=0, n, k1=0, k2=0;

    cin>>n;

    while( i < n )
    {
        cin>>a;
        if( k1 < k2 )
            k1 += a;
        else
            k2 += a;
        i++;
    }

    if( k1 >= k2 )
        cout<<k1-k2<<endl;
    else
        cout<<k2-k1<<endl;

    return 0;
}

________________________
Why no accept???
Re: ACCEPTED!!!
Posted by CodeChomper 2 Nov 2010 08:27
6
1 4 5 6 7 9

the correct answer is 0, but yours is not 0..
Re: ACCEPTED!!!
Posted by esenin.kazan 6 Feb 2011 20:14
to CodeChomper

Why the correct answer is 0?
I got 2:
|(9+5+1)-(7+6+4)|=2
Re: ACCEPTED!!!
Posted by jfr 7 Feb 2011 03:08
to esenin.kazan

9 + 7 = 16
1 + 4 + 5 + 6 = 16

Edited by author 07.02.2011 03:09
Re: ACCEPTED!!!
Posted by Dejan Milinkov 7 Apr 2011 17:28
Read the problem again, your solution doesn't guarantee that the given difference will be minimal.
Re: ACCEPTED!!!
Posted by zxy_snow 11 May 2011 11:30
6 5 4 9 1 1 10  Your code can't get the right answer for this test.
Re: ACCEPTED!!!
Posted by amirani 21 Jul 2011 00:03
in pascal :) accepted

var
   i,j,n,min,s,m: integer;
   orobiti: array  [0..20] of integer;
   a:array [1..20] of integer;
begin
    read (n);
    min:=0;
    for i:=1 to n do
      begin
         read(a[i]);
     min:=min+a[i];
      end;
    while orobiti [0]<>1 do
    begin
       j:=n;
       while orobiti[j]=1 do
       begin
         orobiti[j]:=0;
         j:=j-1;
       end;
       orobiti[j]:=orobiti[j]+1;
       m:=0;
       s:=0;
       for i:=1 to n do
       begin
         if orobiti[i]=0 then
       s:=s+a[i]
     else
           m:=m+a[i];
       end;
       if abs (s-m)< min then
          min:=abs(s-m);
    end;
   writeln (min);
end.