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

Help Me!!!
Posted by nguyen canh toan 22 Sep 2005 21:09
const max       =20;
type  arr       =array [1..max] of longint;
var   W         :arr;
      xet       :array [1..max] of boolean;
      S,S0,
      tong,min  :longint;
      N         :integer;
procedure Sort( var W:arr);
  var i,j            :integer;
      tg             :longint;
begin
   for i:=2 to N do
   begin
      tg:=W[i];
      j:=i-1;
      while (j>0)and(W[j]<tg) do
      begin W[j+1]:=W[j];dec(j);end;
      W[j+1]:=tg;
   end;
end;
procedure ReadInp_Init;
var i     :integer;
begin
   S0:=0;
   readln(N);
   for i:=1 to N do
   begin readln(W[i]);S0:=S0+W[i];end;
   S:=S0 div 2;
   fillchar(xet,sizeof(xet),false);
   Sort(W);
   min:=maxlongint;
   tong:=0;
end;
procedure Find( k,i:integer);
  var j   :integer;
begin
   for j:=i to N do
   if (not xet[j])and(tong+W[j]<=S) then
   begin
      xet[j]:=true;
      tong:=tong+W[j];
      if (abs(2*tong-S0)<min) then min:=abs(2*tong-S0);
      Find(k+1,j+1);
      xet[j]:=false;
      tong:=tong-W[j];
   end;
end;
BEGIN
ReadInp_Init;
Find(1,1);
Write(min);
END.

I submited this program but i got WrongAnswer at Test1, while i have correct answer when i test it in my PC, why???
Re: Help Me!!!
Posted by Dulat_KBTU 6 Feb 2006 09:03
Idon't know I have same problem
nguyen canh toan wrote 22 September 2005 21:09
const max       =20;
type  arr       =array [1..max] of longint;
var   W         :arr;
      xet       :array [1..max] of boolean;
      S,S0,
      tong,min  :longint;
      N         :integer;
procedure Sort( var W:arr);
  var i,j            :integer;
      tg             :longint;
begin
   for i:=2 to N do
   begin
      tg:=W[i];
      j:=i-1;
      while (j>0)and(W[j]<tg) do
      begin W[j+1]:=W[j];dec(j);end;
      W[j+1]:=tg;
   end;
end;
procedure ReadInp_Init;
var i     :integer;
begin
   S0:=0;
   readln(N);
   for i:=1 to N do
   begin readln(W[i]);S0:=S0+W[i];end;
   S:=S0 div 2;
   fillchar(xet,sizeof(xet),false);
   Sort(W);
   min:=maxlongint;
   tong:=0;
end;
procedure Find( k,i:integer);
  var j   :integer;
begin
   for j:=i to N do
   if (not xet[j])and(tong+W[j]<=S) then
   begin
      xet[j]:=true;
      tong:=tong+W[j];
      if (abs(2*tong-S0)<min) then min:=abs(2*tong-S0);
      Find(k+1,j+1);
      xet[j]:=false;
      tong:=tong-W[j];
   end;
end;
BEGIN
ReadInp_Init;
Find(1,1);
Write(min);
END.

I submited this program but i got WrongAnswer at Test1, while i have correct answer when i test it in my PC, why???
Re: Help Me!!!
Posted by Ayhan Aliyev [BOTL] 6 Feb 2006 11:24
Use read insead of readln