I have AC this code in another site:
http://www.olymp.vinnica.ua/alltask/task.shtml?coinsBut here a have WA1. Wats wrong in my code?
program Stone_pile;
const size=20;
var a:array[1..20]of longint;
c:array[0..size] of shortint;
i,g1,g2,raz,j,z,kol,n:longint;
procedure ReadFile;
begin
{ assign(input,'in.txt');
reset(input);}
read(n);
for i:=1 to n-1 do readln(a[size-i+1]);
readln(a[1]);
fillchar(c,sizeof(c),0);
kol:=1;
for i:=1 to n-1 do kol:=kol*2;
dec(kol);
raz:=MaxLongint;
end;
begin
ReadFile;
for z:=1 to kol+1 do
begin
g1:=a[1];
g2:=0;
for j:=size downto size-n+2 do
if c[j]=0 then inc(g1,a[j])
else inc(g2,a[j]);
if abs(g1-g2)<raz then raz:=abs(g1-g2);
inc(c[size]);
for j:=size downto size-n+2 do if c[j]>1 then
begin
inc(c[j-1],c[j] div 2);
c[j]:=c[j] mod 2;
end;
end;
writeln(raz);
end.