TWO - Lập lịch trên 2 máy
Tác giả: flashmt
Ngôn ngữ: Pascal
const fi='';
fo='';
maxn=10000;
type ar=array[1..maxn] of longint;
var a,b,a1,b1,d1,a2,b2,d2:ar;
n,n1,n2:longint; re:int64;
procedure rf;
var i:longint;
begin
read(n);
for i:=1 to n do read(a[i]);
for i:=1 to n do read(b[i]);
n1:=0; n2:=0;
for i:=1 to n do
if a[i]<=b[i] then
begin
inc(n1);
a1[n1]:=a[i]; b1[n1]:=b[i]; d1[n1]:=i;
end
else
begin
inc(n2);
a2[n2]:=a[i]; b2[n2]:=b[i]; d2[n2]:=i;
end;
end;
procedure sort(l,r:longint);
var i,j,x,t:longint;
begin
i:=l; j:=r; x:=a1[(i+j) shr 1];
repeat
while a1[i]<x do i:=i+1;
while a1[j]>x do j:=j-1;
if i<=j then
begin
t:=b1[i]; b1[i]:=b1[j]; b1[j]:=t;
t:=a1[i]; a1[i]:=a1[j]; a1[j]:=t;
t:=d1[i]; d1[i]:=d1[j]; d1[j]:=t;
i:=i+1; j:=j-1;
end;
until i>j;
if i<r then sort(i,r);
if l<j then sort(l,j);
end;
procedure sort1(l,r:longint);
var i,j,x,t:longint;
begin
i:=l; j:=r; x:=b2[(i+j) shr 1];
repeat
while b2[i]>x do i:=i+1;
while b2[j]<x do j:=j-1;
if i<=j then
begin
t:=b2[i]; b2[i]:=b2[j]; b2[j]:=t;
t:=a2[i]; a2[i]:=a2[j]; a2[j]:=t;
t:=d2[i]; d2[i]:=d2[j]; d2[j]:=t;
i:=i+1; j:=j-1;
end;
until i>j;
if i<r then sort1(i,r);
if l<j then sort1(l,j);
end;
procedure pr;
var i:longint; x:int64;
begin
re:=0; x:=0;
for i:=1 to n1 do
begin
x:=x+a1[i];
if x>re then re:=x;
re:=re+b1[i];
end;
for i:=1 to n2 do
begin
x:=x+a2[i];
if x>re then re:=x;
re:=re+b2[i];
end;
writeln(re);
for i:=1 to n1 do write(d1[i],' ');
for i:=1 to n2 do write(d2[i],' ');
end;
begin
assign(input,fi); reset(input);
assign(output,fo); rewrite(output);
rf;
sort(1,n1);
sort1(1,n2);
pr;
close(input); close(output);
end.