|
|
back to boardwhy crash(access violation)? Posted by Rustam 28 Mar 2008 22:24 program p1009; {$APPTYPE CONSOLE} uses SysUtils; var n,k:longint; mas:array [0..25] of longint; a:array [1..25] of longint; min:longint; procedure init; var i:longint; begin fillchar(mas,sizeof(mas),0); fillchar(a,sizeof(a),0); read(n); for i:=1 to n do read(a[i]); end; procedure print; begin write(min); halt(0); end; function sc:longint; var s1,s2,i:longint; begin s1:=0; s2:=0; for i:=1 to n do if mas[i]=0 then inc(s1,a[i]) else inc(s2,a[i]); result:=abs(s1-s2); end; procedure generat; var i,j:longint; begin if mas[0]<>0 then print else begin j:=n; while mas[j]>0 do dec(j); mas[j]:=1; for i:=j+1 to n do mas[i]:=0; k:=sc; if k<min then min:=k; generat; end; end; begin init; min:=sc; generat; print; end. |
|
|