Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. #include <cstdio>
  2. int main() {
  3. int n, arr[101][101] = {};
  4. while (scanf("%d", &n) != EOF) {
  5. for (int i = 1; i <= n; ++i) {
  6. for (int j = 1; j <= n; ++j) {
  7. scanf("%d", &arr[i][j]);
  8. }
  9. }
  10. int col_sum[101][101] = {};
  11. for (int i = 1; i <= n; ++i) {
  12. for (int j = 1; j <= n; ++j) {
  13. col_sum[i][j] = col_sum[i - 1][j] + arr[i][j];
  14. }
  15. }
  16. int ans = -128, sum;
  17. for (int i = 0; i <= n; ++i) {
  18. for (int j = i + 1; j <= n; ++j) {
  19. sum = 0;
  20. for (int row = 1; row <= n; ++row) {
  21. sum = sum + col_sum[j][row] - col_sum[i][row];
  22. if (sum > ans) ans = sum;
  23. if (sum < 0) sum = 0;
  24. }
  25. }
  26. }
  27. printf("%d\n", ans);
  28. }
  29. return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement