MACHINE - Lập lịch trên 3 máy

Tác giả: flashmt

Ngôn ngữ: Pascal

const fi='';
      fo='';
      maxn=10010;
var n,n1,n2:longint;
    re:int64;
    a,b,c,a1,b1,d1,a2,b2,d2:array[1..maxn] of longint;

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]);
     for i:=1 to n do read(c[i]);
     for i:=1 to n do
         if a[i]+b[i]<=b[i]+c[i] then
         begin
              inc(n1);
              a1[n1]:=a[i]+b[i];
              b1[n1]:=b[i]+c[i];
              d1[n1]:=i;
         end
         else
         begin
              inc(n2);
              a2[n2]:=a[i]+b[i];
              b2[n2]:=b[i]+c[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:=a1[i]; a1[i]:=a1[j]; a1[j]:=t;
                t:=b1[i]; b1[i]:=b1[j]; b1[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:=a2[i]; a2[i]:=a2[j]; a2[j]:=t;
                t:=b2[i]; b2[i]:=b2[j]; b2[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,y:int64;
begin
     x:=0; y:=0; re:=0;
     for i:=1 to n1 do
     begin
          x:=x+a[d1[i]];
          if x>y then y:=x;
          y:=y+b[d1[i]];
          if y>re then re:=y;
          re:=re+c[d1[i]];
     end;
     for i:=1 to n2 do
     begin
          x:=x+a[d2[i]];
          if x>y then y:=x;
          y:=y+b[d2[i]];
          if y>re then re:=y;
          re:=re+c[d2[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.

Download