fork download
  1. #include <iostream>
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4.  
  5. int main() {
  6. int n ; cin>>n;
  7. int x,y;
  8. cin>>x>>y;
  9. vector<vector<int>>points(n,vector<int>(2,0));
  10. int xmax = INT_MIN , ymax =INT_MIN;
  11. for(int i = 0 ; i<n;i++){
  12. cin>>points[i][0]>>points[i][1];
  13. xmax=max(points[i][0],xmax);
  14. ymax = max(points[i][1],ymax);
  15. }
  16. vector<vector<int>>matrix(xmax+1,vector<int>(ymax+1,0));
  17. vector<vector<int>>pre(xmax+1,vector<int>(ymax+1,0));
  18. for(int i = 0 ;i<n;i++){
  19. int x = points[i][0];
  20. int y = points[i][1];
  21. matrix[x][y]=1;
  22. }
  23.  
  24. for(int i = 1 ; i<=xmax;i++){
  25. for(int j = 1; j<=ymax;j++){
  26. pre[i][j]=pre[i-1][j]+pre[i][j-1]-pre[i-1][j-1]+matrix[i][j];
  27. }
  28. }
  29. int maxpoints = 0 ;
  30. for(int i = x ; i<=xmax;i++){
  31. for(int j = y; j<=ymax;j++){
  32. int points = pre[i][j]-pre[i-x][j]-pre[i][j-y]+pre[i-x][j-y];
  33. maxpoints = max(maxpoints,points);
  34. }
  35. }
  36. cout<<maxpoints;
  37.  
  38. // your code goes here
  39. return 0;
  40. }
Success #stdin #stdout 0s 5324KB
stdin
5
2 2
1 1
2 3 
2 4
3 4
5 5
stdout
3