记录编号 |
122373 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[UVa 11292] 勇者斗恶龙 |
最终得分 |
100 |
用户昵称 |
FoolMike |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.015 s |
提交时间 |
2014-09-23 13:04:39 |
内存使用 |
0.32 MiB |
显示代码纯文本
var
n,m,ans,c,d,e:longint;
a,b:array[1..20000]of longint;
procedure kuaipai(l,r:longint);
var
i,j,x,y:longint;
begin
i:=l;j:=r;x:=b[(l+j)div 2];
repeat
while b[i]<x do inc(i);
while b[j]>x do dec(j);
if i<=j then
begin
y:=b[i];b[i]:=b[j];b[j]:=y;
inc(i);dec(j);
end;
until i>j;
if i<r then kuaipai(i,r);
if j>l then kuaipai(l,j);
end;
procedure kuaipai2(l,r:longint);
var
i,j,x,y:longint;
begin
i:=l;j:=r;x:=a[(l+j)div 2];
repeat
while a[i]<x do inc(i);
while a[j]>x do dec(j);
if i<=j then
begin
y:=a[i];a[i]:=a[j];a[j]:=y;
inc(i);dec(j);
end;
until i>j;
if i<r then kuaipai2(i,r);
if j>l then kuaipai2(l,j);
end;
begin
assign(input,'DragonUVa.in');
reset(input);
assign(output,'DragonUVa.out');
rewrite(output);
repeat
ans:=0;
readln(n,m);
for n:=1 to n do
readln(a[n]);
for m:=1 to m do
readln(b[m]);
if n>m then
begin
ans:=-1;
writeln('Loowater is doomed');
end;
if ans<>-1 then
begin
e:=0;
kuaipai(1,m);
kuaipai2(1,n);
d:=1;
for c:=1 to n do
begin
if d=m+1 then
begin
writeln('Loowater is doomed');
e:=1;
break;
end;
while b[d]<a[c] do
begin
inc(d);
if d=m+1 then
begin
writeln('Loowater is doomed');
e:=1;
break;break;
end;
end;
ans:=ans+b[d];
inc(d);
end;
if e=0 then writeln(ans);
end;
until eof;
close(input);close(output);
end.