fork download
  1.  
  2. #include <bits/stdc++.h>
  3.  
  4. //#define int long long
  5. #define all(v) v.begin(),v.end()
  6. using namespace std;
  7. #define ll long long
  8. const int MOD = 1e9 + 7;
  9. const int N = 1e5 + 10;
  10. const double EPS = 1e-9;
  11. const double PI = acos(-1);
  12. const long long md = 1e9 + 7;
  13. #define MAX 1000007
  14. #define ld long double
  15. int dx[] = {-1, 0, 1, -1, -1, 1, 0, 1};
  16. int dy[] = {-1, -1, -1, 1, 0, 1, 1, 0};
  17.  
  18. void sol() {
  19. int n, m, k;
  20. cin >> n >> m >> k;
  21. map<int, set<int>> a, b;
  22. map<pair<int, int>, bool> mp;
  23. vector<pair<int, int>> v(k);
  24. for (int i = 0; i < k; i++) {
  25. cin >> v[i].first >> v[i].second;
  26. mp[{v[i].first, v[i].second}] = 1;
  27. a[v[i].first].insert(v[i].first);
  28. b[v[i].second].insert(v[i].second);
  29. }
  30. sort(all(v));
  31. int mx = 0, x = -1, y = -1;
  32. for (int i = 0; i < k; i++) {
  33. for (int dir = 0; dir < 8; dir++) {
  34. int nx = v[i].first + dx[dir];
  35. int ny = v[i].second + dy[dir];
  36. if (nx > 0 && ny > 1 && nx <= n && ny <= m && mp.count({nx, ny}) == 0) {
  37. int mX = 0, mY = 0;
  38. if (a.count(nx))
  39. mX = a[nx].size();
  40. if (b.count(ny))
  41. mY = b[ny].size();
  42. if (max(mX, mY) >= mx) {
  43. mx = max(mX, mY);
  44. if (x != -1) {
  45.  
  46. } else {
  47. x = nx;
  48. y = ny;
  49. }
  50. }
  51. }
  52. }
  53. }
  54. if (!mx) {
  55. cout << 0 << endl;
  56. cout << "0 0";
  57. } else {
  58. cout << mx << endl;
  59. cout << x << " " << y;
  60. }
  61.  
  62. }
  63.  
  64. signed main() {
  65.  
  66. ios::sync_with_stdio(0);
  67. cin.tie(0);
  68.  
  69. int t = 1;
  70. //cin >> t;
  71. while (t--) {
  72. sol();
  73. }
  74.  
  75. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
0
0 0