- Code: Select all
var p,pi,t,len,n,w,i,tot:longint;
l,r:array[0..10000]of double;
now,max:double;
flag:boolean;
procedure qsort(x,y:longint);
var i,j:longint;
k,temp:double;
begin
i:=x;j:=y;k:=l[(i+j) div 2];
repeat
while l[i]<k do inc(i);
while l[j]>k do dec(j);
if not (i>j) then begin
temp:=l[i];l[i]:=l[j];l[j]:=temp;
temp:=r[i];r[i]:=r[j];r[j]:=temp;
inc(i);dec(j);
end;
until i>j;
if x<j then qsort(x,j);
if i<y then qsort(i,y);
end;
begin
while not eof do begin
readln(n,len,w);
t:=0;
for i:=1 to n do begin
readln(p,pi);
if pi>w/2 then begin
inc(t);
l[t]:=p-sqrt(sqr(pi)-sqr(w/2));
if l[t]<0 then l[t]:=0;
r[t]:=p+sqrt(sqr(pi)-sqr(w/2));
if r[t]>len then r[t]:=len;
//writeln(l[t],' ',r[t]);
end;
end;
qsort(1,t);
now:=0;
i:=1;
tot:=0;
flag:=true;
while now<len do begin
max:=0;
while (l[i]<=now) and (i<=t) do begin
if r[i]>max then max:=r[i];
inc(i);
end;
if max=0 then begin
writeln(-1);
flag:=false;
break;
end;
now:=max;
inc(tot);
end;
if flag then writeln(tot);
end;
end.
I test many cases,and it's no problem.But online-judge says "runtime error".I check the program over and over again,but i still can not find any mistake.could you help me?
