fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // your code goes here
  13. Scanner sc=new Scanner(System.in);
  14. int t=sc.nextInt();
  15. while(t-->0)
  16. {
  17. int n=sc.nextInt();
  18. long x[]=new long[n];
  19. long y[]=new long[n];
  20.  
  21. for(int i=0;i<n;i++)
  22. {
  23.  
  24. x[i]=sc.nextLong();
  25. y[i]=sc.nextLong();
  26. }
  27.  
  28. Arrays.sort(x);
  29. Arrays.sort(y);
  30.  
  31. long minarea;
  32. if(n<=0)
  33. minarea=0;
  34. else if(n==1)
  35. minarea=1;
  36. else
  37. {
  38. minarea=( (x[n-1]-x[0]+1)*(y[n-1]-y[0]+1));
  39.  
  40. // removing left x
  41. long area1=( (x[n-1]-x[1]+1)*(y[n-1]-y[0]+1));
  42. minarea=Math.min(minarea,area1);
  43.  
  44. // removing right x
  45. long area2=( (x[n-2]-x[0]+1)*(y[n-1]-y[0]+1));
  46. minarea=Math.min(minarea,area2);
  47.  
  48. // removing left y
  49. long area3=( (x[n-1]-x[0]+1)*(y[n-1]-y[1]+1));
  50. minarea=Math.min(minarea,area3);
  51.  
  52. // removing right y
  53. long area4=( (x[n-1]-x[0]+1)*(y[n-2]-y[0]+1));
  54. minarea=Math.min(minarea,area4);
  55.  
  56. // removing left x , down y
  57. long area5=( (x[n-1]-x[1]+1)*(y[n-1]-y[1]+1));
  58. minarea=Math.min(minarea,area5);
  59.  
  60.  
  61. // removing right x, top y
  62. long area6=( (x[n-2]-x[0]+1)*(y[n-2]-y[0]+1));
  63. minarea=Math.min(minarea,area6);
  64. }
  65.  
  66. System.out.println(minarea);
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73. }
  74. }
  75. }
Success #stdin #stdout 0.19s 56632KB
stdin
7
3
1 1
1 2
2 1
5
1 1
2 6
6 4
3 3
8 2
4
1 1
1 1000000000
1000000000 1
1000000000 1000000000
1
1 1
5
1 2
4 2
4 3
3 1
3 2
3
1 1
2 5
2 2
4
4 3
3 1
4 4
1 2
stdout
1
24
1000000000000000000
1
4
4
6