Skip to content

Instantly share code, notes, and snippets.

@tarawa
Created May 13, 2013 12:58
Show Gist options
  • Save tarawa/5568145 to your computer and use it in GitHub Desktop.
Save tarawa/5568145 to your computer and use it in GitHub Desktop.
URAL1019 (Pascal)
type
xyz=record
x,y:longint;
z:char;
end;
var
n,i,j,ans,max,left,right,mleft,mright,k:longint;
f:array [0..10010] of boolean;
origin:array [0..10010] of xyz;
a:array [0..10010] of longint;
temp:xyz;
procedure qsort(l,r:longint);
var
i,j,m:longint;
begin
i:=l; j:=r;
m:=a[(l+r) shr 1];
repeat
while a[i]<m do inc(i);
while a[j]>m do dec(j);
if i<=j then
begin
a[0]:=a[i]; a[i]:=a[j]; a[j]:=a[0];
inc(i); dec(j);
end;
until i>j;
if l<j then qsort(l,j);
if r>i then qsort(i,r);
end;
function find(p,l,r:longint):longint;
var
m:longint;
begin
m:=(l+r) shr 1;
if a[m]=p then exit(m) else
if a[m]>p then exit(find(p,l,m-1)) else
exit(find(p,m+1,r));
end;
procedure printresult;
var
i,t,l,r:longint;
ans,ansl,ansr:longint;
begin
i:=1;
ans:=0; ansl:=0; ansr:=0;
repeat
if f[i] then
begin
l:=i; r:=i+1; t:=0;
while (r<=2*n) and (f[r]) do inc(r);
t:=a[r]-a[l];
if t>ans then
begin
ans:=t;
ansl:=l;
ansr:=r;
end;
i:=r;
end;
inc(i);
until i>=2*n;
writeln(a[ansl],' ',a[ansr]);
end;
begin
readln(n);
inc(n);
with origin[1] do
begin
x:=0; y:=trunc(1e9);
z:='w';
end;
a[1]:=0;
a[2]:=origin[1].y;
for i:=2 to n do
begin
with origin[i] do readln(x,y,z,z);
a[i shl 1-1]:=origin[i].x;
a[i shl 1]:=origin[i].y;
end;
qsort(1,2*n);
fillchar(f,sizeof(f),0);
a[0]:=0;
for i:=1 to 2*n-1 do
for j:=1 to n do
if (a[i]>=origin[j].x) and (a[i+1]<=origin[j].y) then
if origin[j].z='w' then f[i]:=true else f[i]:=false;
printresult;
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment