Mi scuso per le seguenti sviste
codice:
if   max>a[j] then   max:=a[j];

va sostituito con 

if   max<a[j] then   max:=a[j];

e

b[j]:=FALSE;

con

b[i]:=FALSE;