|
|
вернуться в форум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!!! 6 1 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!!! Послано jfr 7 фев 2011 03:08 to 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!!! 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. |
|
|