1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| #include <bits/stdc++.h> using namespace std;
#define IO ios::sync_with_stdio(0);cin.tie(0); #define endl '\n' typedef long long ls; const int N = 510;
int atx[13] = {-2,-1,-1,-1,0,0,0,0,0,1,1,1,2}; int aty[13] = {0,-1,0,1,-2,-1,0,1,2,-1,0,1,0};
void sol(){ int n, m, q; cin >> n >> m >> q; vector<vector<int> > v(n+1, vector<int> (m+1)); vector<vector<ls> > cnt(n+1, vector<ls> (m+1)); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> v[i][j]; ls maxn = -1; int xx, yy; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++){ ls sum = 0; for (int k = 0; k < 13; k++){ int sx = i + atx[k]; int sy = j + aty[k]; if (sx>=1&&sx<=n&&sy>=1&&sy<=m) sum += v[sx][sy]; } cnt[i][j] = sum; if (sum > maxn){ maxn = sum; xx = i; yy = j; } } while (q--){ int x, y, add; cin >> x >> y >> add; ls maxx = -1; int tx, ty; for (int k = 0; k < 13; k++){ int sx = x + atx[k]; int sy = y + aty[k]; if (sx>=1&&sx<=n&&sy>=1&&sy<=m){ cnt[sx][sy] += add; if (cnt[sx][sy] > maxx){ maxx = cnt[sx][sy]; tx = sx, ty = sy; } } } if (maxx > maxn){ maxn = maxx; xx = tx; yy = ty; } cout << xx << ' ' << yy << endl; } }
int main(){ IO
sol();
}
|