fork(1) download
  1. var z:array[1..10000] of int64;
  2. n,i,j,k:integer;
  3. mn,tot:int64;
  4.  
  5. procedure qs(start,stop:integer);
  6. var temp,pivot:longint;left,right:integer;
  7. begin
  8. if start>=stop then
  9. else
  10. begin
  11. pivot:=z[start];
  12. left:=start+1;
  13. right:=stop;
  14. while(left<=right) do
  15. begin
  16. while(left<=stop) and (z[left]<pivot) do inc(left);
  17. while(right>start) and (z[right]>=pivot)do dec(right);
  18. if left<right then
  19. begin
  20. temp:=z[left];
  21. z[left]:=z[right];
  22. z[right]:=temp;
  23. end;
  24. end;
  25. temp:=z[start];
  26. z[start]:=z[right];
  27. z[right]:=temp;
  28. qs(start,right-1);
  29. qs(right+1,stop);
  30. end;
  31. end;
  32.  
  33.  
  34. begin
  35. read(n);
  36. for i:=1 to n do
  37. begin
  38. read(z[i]);
  39. end;
  40. qs(1,n);
  41. for i:=1 to n-2 do
  42. begin
  43. for j:=i+1 to n-1 do
  44. begin
  45. mn:=z[i]+z[j];
  46. for k:=j+1 to n do
  47. begin
  48. if z[k]<mn then writeln(z[i],' ',z[j],' ',z[k]);
  49. end;
  50. end;
  51. end;
  52. end.
Success #stdin #stdout 0.01s 332KB
stdin
6
3 1 5 1 4 7
stdout
3 4 5
3 5 7
4 5 7