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

1005
Posted by olzii 18 Mar 2007 14:21
what's wrong???
i get 'wrong answer'
help


var
c,a:array[1..1000] of integer;
u,h,p,y,t,k,j,i,n:integer;
min:longint;
begin
  assign(input,'sto.in');reset(input);
  assign(output,'sto.out');rewrite(output);
    readln(n);  k:=1; min:=1000000;
     for i:=1 to n do
       begin
         readln(a[i]);
         k:=k*2;
       end;
     repeat
      inc(i);
        begin
           p:=i;
           for j:=1 to n do
              begin
                c[j]:=p mod 2;
                p:=p div 2;
              end;
            y:=0; t:=0;
              for j:=1 to n do
                 begin
                   if c[j]=0 then y:=y+a[j];
                   if c[j]=1 then t:=t+a[j];
                 end;
            u:=abs(y-t);
            if min>u then min:=u;
         end;
    until i=k;
     write(min);
  close(input);close(output);
end.

Edited by author 18.03.2007 14:22