[an error occurred while processing this directive]
Listing SEFUL.PAS
program seful;
uses Crt;
type tip=record
p:Byte;
val:Word
end;
var a,b,c:array[1..100] of Word;
p:array[1..100] of tip;
gresit:set of Byte;
n,i,j,k,sef:Byte;
t:tip;
m,max,pmax,psef,pm:Word;
label l1;
Begin
Clrscr;
Write('introduceti n '); Readln(n);
for i:=1 to n do
begin
Write('Suma celui de-al',i,'-lea copil ');
Readln(a[i]);
for j:=1 to i-1 do
if a[j]=a[i] then gresit:=gresit+[i]
end;
if gresit<>[] then
begin
Write('Copiii ');
for i:=1 to n do
if (i in gresit) then Write(i,' ');
Writeln('nu au ales corect suma');
Write('Nu exista solutie ptr. ');
Writeln('punctul b'); Halt(0)
end
else Writeln('Sume corecte');
for i:=1 to n do
begin
sef:=i; b:=a;
for j:=sef+1 to n do
begin
if sef-(j-sef)>0 then
begin
b[sef-(j-sef)]:=b[sef-(j-sef)]+b[j];
b[j]:=0
end
end;
m:=0;
for j:=1 to n do
if b[j]>m
then begin pm:=j; m:=b[j] end;
if m>max then
begin
c:=b; max:=m; psef:=sef; pmax:=pm
end
end;
Writeln('Sef ',psef);
Write('Dupa donatie ');
for i:=1 to n do write(c[i], ' ');
Writeln('Cel mai bogat ',pmax,' cu ',max);
Readln
End.