This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
#include <algorithm>
using namespace std;
int n, m;
long long a[301][301];
long long s[301][301];
long long d[301][301];
long long w[301][301][302];
int main ()
{
scanf ("%d%d", &n, &m);
for (int i=1; i<=n; i++) for (int j=1; j<=m; j++) {
scanf ("%lld", &a[i][j]);
s[i][j] = s[i-1][j] + s[i][j-1] - s[i-1][j-1] + a[i][j];
}
for (int i=1; i<=n; i++) {
for (int j=1; j<=m; j++) {
d[i][j] = s[i][j];
if (j>=2) {
for (int a=1; a<i; a++) {
if (d[i][j] < w[a][i][j] + s[i][j] - s[a][j])
d[i][j] = w[a][i][j] + s[i][j] - s[a][j];
}
for (int a=1; a<i; a++)
w[a][i][j+1] = max (w[a][i][j], d[a][j] + s[a][j] - s[i][j]);
}
else {
for (int a=1; a<i; a++)
w[a][i][j+1] = d[a][j] + s[a][j] - s[i][j];
}
}
}
printf ("%lld\n", d[n][m]);
return 0;
}
/*
2 2
1 -1
-1 1
5 5
4 -2 3 -4 2
-2 1 1 4 -2
-3 1 -1 2 5
2 -4 2 3 5
1 -4 4 -1 -2
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |