CAR - Lập lịch sửa chữa ô tô
Tác giả: flashmt
Ngôn ngữ: Pascal
const maxn=10001;
var n:longint;
re:qword;
a,b,c:array[1..maxn] of longint;
procedure rf;
var i:longint;
begin
readln(n);
for i:=1 to n do read(a[i]);
for i:=1 to n do read(b[i]);
for i:=1 to n do c[i]:=i;
end;
procedure sort(l,r:longint);
var i,x,j,y,u:longint;
begin
i:=l; j:=r; x:=a[(i+j) shr 1]; y:=b[(i+j) shr 1];
repeat
while a[i]*y>b[i]*x do i:=i+1;
while a[j]*y<b[j]*x do j:=j-1;
if i<=j then
begin
u:=a[i]; a[i]:=a[j]; a[j]:=u;
u:=b[i]; b[i]:=b[j]; b[j]:=u;
u:=c[i]; c[i]:=c[j]; c[j]:=u;
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 pr;
var i,t:longint; u:qword;
begin
sort(1,n);
re:=0; t:=0;
for i:=1 to n do
begin
t:=t+b[i];
u:=a[i]; u:=u*t;
re:=re+u;
end;
end;
procedure wf;
var i:longint;
begin
writeln(re);
for i:=1 to n do write(c[i],' ');
end;
begin
rf;
pr;
wf;
end.