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

Common Board

When a bag???
Posted by APS 18 Aug 2004 01:32
Proga #1005 wrong on test 1. When a bag???
program hdfj;
var
   a:array[1..10000]of longint;
   b:array[1..30]of longint;
   i,j,k,n,sum,ans,top:longint;
begin
     read(n);
     sum:=0;
     for i:=1 to n do
         begin
              read(b[i]);
              sum:=sum+b[i];
         end;
     fillchar(a,sizeof(a),0);
     a[1]:=0;
     top:=1;
     for i:=1 to n do
         begin
              k:=top;
              for j:=1 to k do
                  begin
                       inc(top);
                       a[top]:=a[j]+b[i];
                  end;
         end;
     ans:=sum;
     for i:=1 to top do
         begin
             if ans>abs(sum-a[i]*2) then ans:=abs(sum-a[i]*2);
         end;
    write(ans);
end.