fork download
  1. program sushi;
  2. Uses Math;
  3. const MAXN=100000;
  4. type piatto = record
  5. inizio:longint;
  6. durata:longint;
  7. peso:longint;
  8. fine:longint;
  9. end;
  10. elenco = array[0.. MAXN-1] of Longint;
  11. table = array[0..MAXN-1] of piatto;
  12. var N,i, ricordafine:Longint;
  13. quantomangio:int64;
  14. T : table;
  15. S,W,D,E, ricordaindice:elenco; (*array riferiti ai piatti Start, Weigth, Durata, End*)
  16.  
  17. Procedure scambia (var a,b: longint);
  18. var x:longint;
  19. begin
  20. x:=a;
  21. a:=b;
  22. b:=x;
  23. end;
  24.  
  25. Procedure ordinamento (estremoi,estremos: longint; var v : elenco; var u:elenco; ordinato:boolean);
  26. var inf, sup, medio:longint;
  27. pivot :longint;
  28. begin
  29. inf:=estremoi;
  30. sup:=estremos;
  31. medio:= (estremoi+estremos) div 2;
  32. pivot:=v[medio];
  33. repeat
  34. if (ordinato) then
  35. begin
  36. while (v[inf]<pivot) do inf:=inf+1;
  37. while (v[sup]>pivot) do sup:=sup-1;
  38. end;
  39. if inf<=sup then
  40. begin
  41. scambia(v[inf],v[sup]);
  42. scambia(u[inf],u[sup]);
  43. inf:=inf+1;
  44. sup:=sup-1;
  45. end;
  46. until inf>sup;
  47. if (estremoi<sup) then ordinamento(estremoi,sup,v,u,ordinato);
  48. if (inf<estremos) then ordinamento(inf,estremos,v,u,ordinato);
  49. end;
  50.  
  51. begin
  52. readln(N);
  53. for i:=0 to N-1 do ricordaindice[i]:=i;
  54. for i:=0 to N-1 do
  55. begin
  56. { dish on table }
  57. readln(S[i],W[i],D[i]);
  58. E[i]:=S[i]+D[i];
  59. T[i].inizio:=S[i];
  60. T[i].durata:=D[i];
  61. T[i].peso:=W[i];
  62. T[i].fine:=E[i];
  63. end;
  64. ordinamento(0,N-1,E, ricordaindice,true);
  65. for i:=0 to N-1 do write(E[i],' ',ricordaindice[i],' ');writeln;
  66. quantomangio:=T[ricordaindice[0]].peso;
  67. ricordafine:=T[ricordaindice[0]].fine;
  68. for i:=1 to N-1 do
  69. begin
  70. if ((E[i]=ricordafine) and (i=1)) then quantomangio:=max(quantomangio,T[ricordaindice[i]].peso )
  71. else
  72. begin
  73. if T[ricordaindice[i]].inizio>=ricordafine then begin quantomangio:=quantomangio+T[ricordaindice[i]].peso; ricordafine:=T[ricordaindice[i]].fine; end
  74. else continue;
  75. end;
  76. end;
  77. writeln(quantomangio);
  78. end.
Success #stdin #stdout 0s 5280KB
stdin
4
6 24 3
8 16 5
17 4 1
11 11 2


stdout
9 0 13 3 13 1 18 2 
39