fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5. #define print(a) for(auto x : a) cout << x << " "; cout << endl
  6.  
  7.  
  8. const int M = 1000000007;
  9. const int N = 3e5+9;
  10. const int INF = 2e9+1;
  11. const int LINF = 2000000000000000001;
  12.  
  13. inline int power(int a, int b, int mod=M) {
  14. int x = 1;
  15. a %= mod;
  16. while (b) {
  17. if (b & 1) x = (x * a) % mod;
  18. a = (a * a) % mod;
  19. b >>= 1;
  20. }
  21. return x;
  22. }
  23.  
  24.  
  25. //_ ***************************** START Below *******************************
  26.  
  27. // 5
  28. // 2 2
  29. // 5
  30. // 1 1
  31. // 2 3
  32. // 3 4
  33. // 2 4
  34. // 5 5
  35.  
  36.  
  37.  
  38. vector<vector<int>> a;
  39.  
  40. int consistency(int n, int x, int y){
  41.  
  42. vector<vector<int>> grid(n, vector<int>(n, 0));
  43. for(auto& p : a){
  44. int x = p[0]-1;
  45. int y = p[1]-1;
  46.  
  47. grid[x][y] = 1;
  48. }
  49.  
  50. vector<vector<int>> prefix(n+1, vector<int>(n+1, 0));
  51. for(int i=1; i<=n; i++){
  52. for(int j=1; j<=n; j++){
  53. prefix[i][j] = prefix[i][j-1] + prefix[i-1][j] - prefix[i-1][j-1] + grid[i-1][j-1];
  54. }
  55. }
  56.  
  57. int ans = 0;
  58.  
  59. for(int i=x-1; i<=n-1; i++){
  60. for(int j=y-1; j<=n-1; j++){
  61.  
  62. int pts = prefix[i+1][j+1] - prefix[i-x+1][j+1] - prefix[i+1][j-y+1] + prefix[i-x+1][j-y+1];
  63.  
  64. ans = max(ans, pts);
  65.  
  66. }
  67. }
  68.  
  69. return ans;
  70.  
  71. }
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87. int practice(int n, int x, int y){
  88.  
  89.  
  90. return 0;
  91. }
  92.  
  93.  
  94.  
  95.  
  96.  
  97. void solve() {
  98.  
  99. int n;
  100. cin >> n;
  101. int x , y;
  102. cin >> x >> y;
  103.  
  104. int m;
  105. cin>> m;
  106.  
  107. a.resize(m);
  108. for(int i=0; i<m; i++){
  109. int p , q;
  110. cin >> p >> q;
  111. a[i] = {p, q};
  112. }
  113.  
  114. cout << consistency(n, x, y) << endl;
  115.  
  116.  
  117. }
  118.  
  119.  
  120.  
  121.  
  122.  
  123. int32_t main() {
  124. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  125.  
  126. int t = 1;
  127. // cin >> t;
  128. while (t--) {
  129. solve();
  130. }
  131.  
  132. return 0;
  133. }
Success #stdin #stdout 0s 5320KB
stdin
5
2 2
5
1 1
2 3
3 4
2 4
5 5
stdout
3