fork(2) download
  1. #include <vector>
  2. #include <list>
  3. #include <map>
  4. #include <set>
  5. #include <deque>
  6. #include <queue>
  7. #include <stack>
  8. #include <bitset>
  9. #include <algorithm>
  10. #include <functional>
  11. #include <numeric>
  12. #include <utility>
  13. #include <sstream>
  14. #include <iostream>
  15. #include <iomanip>
  16. #include <cstdio>
  17. #include <cmath>
  18. #include <cstdlib>
  19. #include <cctype>
  20. #include <string>
  21. #include <cstring>
  22. #include <cstdio>
  23. #include <cmath>
  24. #include <cstdlib>
  25. #include <ctime>
  26. #include <string.h>
  27. #include <fstream>
  28. #include <cassert>
  29. using namespace std;
  30.  
  31. #define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
  32. #define sz(a) int((a).size())
  33. #define rep(i, s, n) for(int i = s; i <= (n); ++i)
  34. #define rev(i, n, s) for(int i = (n); i >= s; --i)
  35. #define fore(x, a) for(auto &&x : a)
  36. typedef long long ll;
  37. const int mod = 1000000007;
  38. const int N = 100005;
  39. const ll inf = mod * 1LL * mod;
  40.  
  41. ll a[21][21][21];
  42.  
  43. int main() {
  44. #ifdef loc
  45. if(!freopen((string(FOLDER) + "inp.txt").c_str(), "r", stdin)) {
  46. assert(0);
  47. }
  48. freopen((string(FOLDER) + "out.txt").c_str(), "w", stdout);
  49. #endif
  50. boost;
  51. int t;
  52. cin >> t;
  53. while (t-- > 0) {
  54. memset(a, 0, sizeof(a));
  55. int l, n, m;
  56. cin >> l >> n >> m;
  57. ll mx = -inf;
  58. rep(i, 1, l) {
  59. rep(j, 1, n) {
  60. rep(k, 1, m) {
  61. cin >> a[i][j][k];
  62. mx = max(mx, a[i][j][k]);
  63. a[i][j][k] += a[i][j - 1][k];
  64. a[i][j][k] += a[i][j][k - 1];
  65. a[i][j][k] -= a[i][j - 1][k - 1];
  66. }
  67. }
  68. }
  69. if (mx < 0) {
  70. cout << mx << endl;
  71. if (t > 0) cout << endl;
  72. continue;
  73. }
  74. ll ans = 0;
  75. rep(i1, 1, n) {
  76. rep(j1, 1, m) {
  77. rep(i2, i1, n) {
  78. rep(j2, j1, m) {
  79. ll cur = 0;
  80. rep(k, 1, l) {
  81. ll p = a[k][i2][j2] - a[k][i1 - 1][j2] - a[k][i2][j1 - 1] + a[k][i1 - 1][j1 - 1];
  82. cur = max(0LL, cur + p);
  83. ans = max(ans, cur);
  84. }
  85. }
  86. }
  87. }
  88. }
  89. cout << ans << endl;
  90. if (t > 0) cout << endl;
  91. }
  92. return 0;
  93. }
Success #stdin #stdout 0s 3536KB
stdin
1
2 2 2
-1 2 0 -3 -2 -1 1 5
stdout
6