|  | 
|  | 
| back to board | ACCEPTED!!! #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!!! 61 4 5 6 7 9
 
 the correct answer is 0, but yours is not 0..
Re: ACCEPTED!!! 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:08to esenin.kazan
 9 + 7 = 16
 1 + 4 + 5 + 6 = 16
 
 Edited by author 07.02.2011 03:09
Re: ACCEPTED!!! Read the problem again, your solution doesn't guarantee that the given difference will be minimal.Re: ACCEPTED!!! 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:03in 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.
 | 
 | 
|