fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. using row = int[100]; int t, h, w; row y, z;
  4. inline int g(int l, int r) { return *max_element(y+l,y+r); }
  5. void solve() {
  6. for (int i = 0; i < h; ++i, memcpy(y,z,sizeof(row)))
  7. for (int j = 0; j < w; cin >> z[j], z[j] += g(max(j-1,0),min(j+2,w)), ++j); }
  8. int main() {
  9. for (cin >> t; t--; memset(y,0,sizeof(row)))
  10. cin >> h >> w, solve(), cout << *max_element(z,z+w) << '\n'; }
Success #stdin #stdout 0s 4400KB
stdin
1
6 5
3 1 7 4 2
2 1 3 1 1
1 2 2 1 8
2 2 1 5 3
2 1 4 4 4
5 2 7 5 1
stdout
32