fork download
  1. #include <cstdio>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6. int t, n, m, i, j, ans;
  7. int a[1005][1005], f[1005][1005];
  8.  
  9. int main() {
  10. scanf("%d", &t);
  11. while (t--) {
  12. scanf("%d%d", &n, &m);
  13. for (int i = 1; i <= n; i++) {
  14. for (int j = 1; j <= m; j++) {
  15. scanf("%d", &a[i][j]);
  16. }
  17. }
  18. ans = a[n][m];
  19. for (int i = 1; i <= n; i++) {
  20. for (int j = 1; j <= m; j++) {
  21. f[i][j] = f[i - 1][j] + f[i][j - 1] - f[i - 1][j - 1] + a[n - i + 1][m - j + 1];
  22. ans = max(ans, f[i][j]);
  23. }
  24. }
  25. printf("%d\n", ans);
  26. }
  27. return 0;
  28. }
Success #stdin #stdout 0s 11352KB
stdin
Standard input is empty
stdout
Standard output is empty