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

My alg is 0 1 knapsack, BUT #4 Crash(Access_Violation)!
Posted by Akshin Salimov 27 Apr 2005 22:21
My alg is 0 1 knapsack, BUT #4 Crash(Access_Violation)!
Need help!

var
a:array[1..100] of longint;
b:array[1..10000] of longint;
max,n,nn,i,s,s2:longint;

procedure readdata;
begin
readln(n);
s:=0;
for i:=1 to n do
begin
read(a[i]);
s:=s+a[i];
end;
s2:=s div 2;
end;

procedure writedata;
begin
writeln(abs( abs(s-max)-abs(max) ));
end;

function check(l:longint):boolean;
var
i:integer;
bb:boolean;

begin
bb:=false;
for i:=1 to nn do
if b[i]=l then
begin
bb:=true;
exit;
end;
check:=false;
end;

procedure sum(l:longint);
var
i,nnn:longint;

begin
nnn:=nn;
for i:=1 to nnn-1 do
begin
if ((b[i]+l)<=s2) and (not check(b[i]+l)) then
begin
if (b[nn]<=s2) and (b[nn]>max) then
max:=b[nn];
inc(nn);
b[nn]:=b[i]+l;
if (b[nn]<=s2) and (b[nn]>max) then
max:=b[nn];
end;
end;
end;

begin
readdata;
nn:=0; max:=a[1];
for i:=1 to n do
begin
if not check(a[i]) then
begin
inc(nn);
b[nn]:=a[i];
if (b[nn]<=s2) and (b[nn]>max) then max:=b[nn];
sum(a[i]);
end;
end;
writedata;
end.
AC! Thanks to Allah!
Posted by Akshin Salimov 28 Apr 2005 14:49
At least AC! Thanks to Allah!
AC!!! 0.001 105 КБ