Код:
//==============================================================================
// проверка на быстрое решение
//==============================================================================
if(n=0) then //если 0 то выводим сообщение
begin
writeln(f_out,'введите n больше 0');
end
else if(n=1) then //если 1 то выводим его время
begin
people[1].status:=true;
writeln(f_out,'>',people[1].xod);
writeln(f_out,'time: ',people[1].xod);
end
else //начинаем вычисления
begin
while(cheak()=true) do //если кто-нибудь остался на левом берегу
begin
//==============================================================================
// 1.берем 2 быстрых переводим на правый берег
//==============================================================================
left_min_1:=search_min(1,0); //самый быстрый
left_min_2:=search_min(left_min_1+1,0); //второй быстрый
people[left_min_1].status:=true;
people[left_min_2].status:=true;
writeln(f_out,'>',people[left_min_1].xod,' ',people[left_min_2].xod);
sum:=sum+people[left_min_2].xod;
//==============================================================================
// проверяем остался ли кто-нибудь и переводим самого быстрого обратно
//==============================================================================
if (cheak()=false) then break //выходим если никого нет
else //возвращаем самого быстрого
begin
rigth:=search_min(1,1); //самый быстрый
people[rigth].status:=false;
writeln(f_out,'<',people[rigth].xod);
sum:=sum+people[rigth].xod;
end;
//==============================================================================
// находим 2 медленных и переводим
//==============================================================================
left_max_1:=search_max(n); //самый быстрый
left_max_2:=search_max(left_max_1-1); //второй быстрый
people[left_max_1].status:=true;
people[left_max_2].status:=true;
writeln(f_out,'>',people[left_max_1].xod,' ',people[left_max_2].xod);
sum:=sum+people[left_max_1].xod;
//==============================================================================
// проверяем остался ли кто-нибудь и переводим самого быстрого обратно
//==============================================================================
if (cheak()=false) then break //выходим если никого нет
else //возвращаем самого быстрого
begin
rigth:=search_min(1,1); //самый быстрый
people[rigth].status:=false;
writeln(f_out,'<',people[rigth].xod);
sum:=sum+people[rigth].xod;
end;
//==============================================================================
// переводим самого быстрого и медленного
//==============================================================================
left_min_1:=search_min(1,0); //самый быстрый
left_max_1:=search_max(n); //самый медленный
people[left_min_1].status:=true;
people[left_max_1].status:=true;
writeln(f_out,'>',people[left_min_1].xod,' ',people[left_max_1].xod);
sum:=sum+people[left_max_1].xod;
//==============================================================================
// проверяем остался ли кто-нибудь и переводим самого быстрого обратно
//==============================================================================
if (cheak()=false) then break //выходим если никого нет
else //возвращаем самого быстрого
begin
rigth:=search_min(1,1); //самый быстрый
people[rigth].status:=false;
writeln(f_out,'<',people[rigth].xod);
sum:=sum+people[rigth].xod;
end;
while(cheak()=true) do
begin
//==============================================================================
// водим быстрого и медленного
//==============================================================================
left_min_1:=search_min(1,0);
left_max_1:=search_max(n);
people[left_min_1].status:=true;
people[left_max_1].status:=true;
writeln(f_out,'>',people[left_min_1].xod,' ',people[left_max_1].xod);
sum:=sum+people[left_max_1].xod;
//==============================================================================
// проверяем остался ли кто-нибудь и переводим самого быстрого обратно
//==============================================================================
if (cheak()=false) then break //выходим если никого нет
else //возвращаем самого быстрого
begin
rigth:=search_min(1,1); //самый быстрый
people[rigth].status:=false;
writeln(f_out,'<',people[rigth].xod);
sum:=sum+people[rigth].xod;
end;
break;
end;
end;
end;
writeln(f_out,'time: ',sum);
close(f_out);
end.