fork download
  1. using System;
  2.  
  3. namespace CodeStorm
  4. {
  5. class Triangles
  6. {
  7. static void Main(string[] args)
  8. {
  9. int n = int.Parse(Console.ReadLine());
  10. string[] A_temp = Console.ReadLine().Split(' ');
  11. int[] A = Array.ConvertAll(A_temp, Int32.Parse);
  12. int[] A_sq = Array.ConvertAll(A, x => x * x);
  13.  
  14. Int64 acute = 0, right = 0, obtuse = 0;
  15. int AiPlusAj = 0;
  16. int squareSum = 0;
  17.  
  18. int max_obtuse = 0;
  19. int max_right = 0;
  20. int max_acute = 0;
  21.  
  22. int n_m_2 = n - 2;
  23. int n_m_1 = n - 1;
  24.  
  25. for (int i = 0; i < n_m_2; i++)
  26. {
  27. for (int j = i + 1; j < n_m_1; j++)
  28. {
  29. AiPlusAj = A[i] + A[j];
  30. squareSum = A_sq[i] + A_sq[j];
  31.  
  32. max_obtuse = Array.BinarySearch(A, j + 1, n - j - 1, AiPlusAj);
  33. max_right = Array.BinarySearch(A_sq, j + 1, n - j - 1, squareSum);
  34. max_acute = max_right < 0 ? ~max_right : max_right;
  35.  
  36. max_obtuse = max_obtuse < 0 ? ~max_obtuse : max_obtuse;
  37. max_right = max_right < 0 ? ~max_right : max_right + 1;
  38.  
  39. obtuse += max_obtuse - max_right;
  40. right += max_right - max_acute;
  41. acute += max_acute - (j + 1);
  42. }
  43. }
  44. Console.WriteLine(acute + " " + right + " " + obtuse);
  45. }
  46. }
  47. }
  48.  
Success #stdin #stdout 0.05s 24048KB
stdin
7
2 3 9 10 12 15 18
stdout
4 1 8