显然我们得到这样几个结论
1.每次攻击对方一定是攻击最大的
2.自己合并也是合并最大和次大的
我们只要穷举下一开始是攻击还是合并,之后就是能攻击先攻击否则就合并
type node=array[..] of int64; var a,b,c,d:node;
j,i,n,m,t1,t2:longint; procedure qsort(var a:node; n:longint);
procedure sort(l,r: longint);
var i,j:longint;
x,y:int64;
begin
i:=l;
j:=r;
x:=a[(l+r) div ];
repeat
while a[i]<x do inc(i);
while x<a[j] do dec(j);
if not(i>j) then
begin
y:=a[i];
a[i]:=a[j];
a[j]:=y;
inc(i);
j:=j-;
end;
until i>j;
if l<j then sort(l,j);
if i<r then sort(i,r);
end; begin
sort(,n);
end; procedure pre;
begin
c:=a;
d:=b;
n:=t1; m:=t2;
end; function work:boolean;
var turn:boolean;
begin
turn:=true;
while true do
begin
if n= then exit(false);
if m= then exit(true);
if turn then
begin
if (c[n]>d[m]) and (m>) then
begin
dec(m);
d[m]:=d[m]+d[m+];
d[m+]:=;
end
else if c[n]<d[m] then
begin
c[n]:=;
dec(n)
end
else exit(true);
end
else begin
if (c[n]>d[m]) then
begin
d[m]:=;
dec(m);
end
else if (c[n]<d[m]) and (n>) then
begin
dec(n);
c[n]:=c[n]+c[n+];
c[n+]:=;
end
else exit(false);
end;
turn:=not turn;
end;
end; function check:boolean;
var fl:boolean;
begin
check:=false;
if a[t1]>b[t2] then
begin
pre;
d[m]:=;
dec(m);
fl:=work;
if fl then exit(true);
end;
if t1> then
begin
pre;
dec(n);
c[n]:=c[n]+c[n+];
c[n+]:=;
fl:=work;
if fl then exit(true);
end;
end; begin
while not eof do
begin
inc(j);
readln(t1,t2);
for i:= to t1 do
read(a[i]);
for i:= to t2 do
read(b[i]);
readln;
qsort(a,t1);
qsort(b,t2);
write('Case ',j,': ');
if check then writeln('Takeover Incorporated')
else writeln('Buyout Limited');
end;
end.