ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1146. Maximum Sum

program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;

    var
    s : array [0..105, 0..105] of integer;
    i, j, max, max1 : integer;
    x, n : shortint;
    q : boolean;

begin
   max := -100;
   max1 := -100;
   q := false;
   read(n);
   for i := 0 to n do
     begin
       s[0, i] := 0;
       s[i, 0] := 0;
     end;
   for i := 1 to n do
   for j := 1 to n do
     begin
       read(x);
       if x >= 0 then q := true;
       if max1 < x then max1 := x;
       s[i, j] := s[i-1,j] + s[i,j-1] + x - s[i-1,j-1];
       if s[i, j] > max then max := s[i, j];
       if s[i, j] < 0 then s[i, j] := 0;
     end;
   if q then  writeLn(max)
   else writeLn(max1);
end.
3
123
456
789

use this matrix to create simple test

for example
3
1 2 3
4 -55 6
7 8 9

end etc...