Pagini recente » Consiliul tribului | Monitorul de evaluare | Diferente pentru preoni-2005/runda-2/solutii intre reviziile 6 si 24 | Conventii de formatare | Cod sursa (job #20153)
Cod sursa(job #20153)
const maxn = 30000;
var fi,fo:text;
n,x,y,i,j,l:longint;
ok:boolean;
a,b:array[1..maxn]of longint;
procedure sorta(l,r:longint);
var i,j,x,y:longint;
begin
i:=l;
j:=r;
x:=a[(l+r) div 2];
repeat
while a[i]<x do i:=i+1;
while x<a[j] do j:=j-1;
if i<=j then
begin
y:=a[i];
a[i]:=a[j];
a[j]:=y;
i:=i+1;
j:=j-1;
end;
until i>j;
if l<j then sorta(l,j);
if i<r then sorta(i,r);
end;
procedure sortb(l,r:longint);
var i,j,x,y:longint;
begin
i:=l;
j:=r;
x:=b[(l+r) div 2];
repeat
while b[i]<x do i:=i+1;
while x<b[j] do j:=j-1;
if i<=j then
begin
y:=b[i];
b[i]:=b[j];
b[j]:=y;
i:=i+1;
j:=j-1;
end;
until i>j;
if l<j then sortb(l,j);
if i<r then sortb(i,r);
end;
procedure writedata;
begin
end;
procedure solve;
begin
i:=1;
j:=1;
ok:=false;
while (i<n*x) and (j<n*y) do
begin
if a[i]<>b[j] then exit;
while a[i]<=b[j] do
begin
inc(i);
if i=n*x then break;
end;
while (a[i]>b[j]) and (b[j+1]=b[j]) do inc(j);
inc(j);
end;
ok:=true;
end;
procedure readdata;
begin
assign(fi,'amlei.in');
assign(fo,'amlei.out');
reset(fi);
rewrite(fo);
while not eof(fi) do
begin
readln(fi,n,x,y);
l:=0;
for i:=1 to n do
begin
for j:=1 to x do
begin
inc(l);
read(fi,a[l]);
end;
end;
sorta(1,l);
l:=0;
for i:=1 to n do
begin
for j:=1 to y do
begin
inc(l);
read(fi,b[l]);
end;
end;
sortb(1,l);
solve;
if ok then writeln(fo,'DA')
else writeln(fo,'NU');
end;
close(fo);
close(fi);
end;
begin
readdata;
end.