clear; clf;
TreatmentTime=[5 4 3 10 8 4 5 7 6 8 9 6 10];
NumberOfPerson=length(TreatmentTime);
for i=1:NumberOfPerson-1
WaitingTime1=[zeros(1,i) ...
cumsum(TreatmentTime(i:end-1))];
WaitingTime2=[zeros(1,i+1) ...
cumsum(TreatmentTime(i+1:end-1))];
ss = floor(WaitingTime1(end)/30);
if ss>0
Alarm = [];
for t=1:ss
    check=(WaitingTime1-30*t).*(WaitingTime2-30*t+0.5);
Alarm=[Alarm find(check<=0)];
end
else
break;
end
set(figure(1),'position',[50 500 1000 500]);
clf;hold on;
for j=1:NumberOfPerson
 if sum(j==Alarm)>0 
  bar(2*j,WaitingTime1(j),'Facecolor','g');
 else
  bar(2*j,WaitingTime1(j),'Facecolor','w'); 
 end
end
for j=i:NumberOfPerson
 if j==i
    bar(2*i,-TreatmentTime(i),'Facecolor','y');
 else
    bar(2*j,-TreatmentTime(j),'Facecolor','b');
    a=num2str(WaitingTime1(j));
    text('FontSize',30,'Interpreter','latex', ...
    'String',a, 'Position', ...
    [2*j-0.25 WaitingTime1(j)+7],'Visible','on');
 end
    b=num2str(TreatmentTime(j));
    text('FontSize',30,'Interpreter','latex', ...
    'String',b, 'Position', ...
 [2*j-0.25 -(TreatmentTime(j)+7)],'Visible','on');
end
axis off
axis([0 2*NumberOfPerson+1 ...
-1.5*max(TreatmentTime) sum(TreatmentTime)])
pause(0.5)
end