fork(5) download
  1. uses math;
  2. const fi='';
  3. fo='';
  4. maxn=5000+2;
  5. var f:array[0..maxn,0..maxn] of longint;
  6. a,b,cs:array[1..maxn] of longint;
  7. res:array[1..maxn] of longint;
  8. dem,n,i,j:Longint;
  9. free:array[1..maxn] of boolean;
  10. procedure nhap;
  11. begin
  12. assign(input,fi);reset(Input);
  13. readln(n);
  14. for i:=1 to n do read(a[i]);
  15. for i:=1 to n do read(b[i]);
  16. close(input);
  17. end;
  18. procedure init;
  19. begin
  20. for i:=1 to n do cs[i]:=i;
  21. end;
  22. procedure swap(var x,y:longint);
  23. var w:longint;
  24. begin
  25. w:=x;x:=y;y:=w;
  26. end;
  27. procedure qs(l,r:longint);
  28. var i,j,x:longint;
  29. begin
  30. i:=l;j:=r;
  31. x:=a[(l+r) div 2];
  32. repeat
  33. while x<a[i] do inc(i);
  34. while x>a[j] do dec(j);
  35. if i<=j then
  36. begin
  37. swap(a[i],a[j]);
  38. swap(b[i],b[j]);
  39. swap(cs[i],cs[j]);
  40. inc(i);dec(j);
  41. end;
  42. until i>j;
  43. if i<r then qs(i,r);
  44. if j>l then qs(l,j);
  45. end;
  46. procedure xuly;
  47. begin
  48. {f[1,0]:=b[1];}
  49. qs(1,n);
  50. for i:=2 to n do
  51. for j:=1 to i div 2 do
  52. begin
  53. f[i,j]:=max(f[i-1,j],f[i-1,j-1]+b[i]);
  54. end;
  55. end;
  56. procedure trace;
  57. begin
  58. i:=n; j:=n div 2;
  59. while (i<>0) and (j<>0) do
  60. begin
  61. if f[i,j]=f[i-1,j-1]+b[i] then
  62. begin
  63. inc(dem);
  64. res[dem]:=i;
  65. free[i]:=true;
  66. dec(i);dec(j);
  67. end else dec(i);
  68. end;
  69. end;
  70. procedure inkq;
  71. begin
  72. assign(output,fo);rewrite(output);
  73. writeln(f[n,n div 2]);
  74. for i:=1 to dem do
  75. begin
  76.  
  77. for j:=res[i]-1 downto 1 do
  78. if free[j]=false then
  79. begin
  80. write(cs[j],' ');
  81. free[j]:=true;
  82. break;
  83. end;
  84. write(cs[res[i]],' ');
  85. writeln;
  86. end;
  87. close(output);
  88. end;
  89. begin
  90. nhap;
  91. init;
  92. xuly;
  93. trace;
  94. inkq;
  95. end.
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.pas:1: warning: missing program header
prog.pas:1: error: module/unit interface `math' could not be imported
stdout
Standard output is empty