Martian Mining
Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std; int dp[][][];
int main()
{
int n,m;
int sumY[][],sumB[][];
int i,j,k,x,y;
while(scanf("%d %d",&n,&m)!=EOF && n!= && m!=)
{
memset(sumY,,sizeof(sumY));
memset(sumB,,sizeof(sumB));
memset(dp,,sizeof(dp));
for(i=;i<=n;i++)
{
for(j=;j<=m;j++)
{
scanf("%d",&x);
sumY[i][j]=sumY[i][j-]+x;
}
}
for(i=;i<=n;i++)
{
for(j=;j<=m;j++)
{
scanf("%d",&y);
sumB[i][j]=sumB[i-][j]+y;
}
} for(i=;i<=n;i++)
{
for(j=;j<=m;j++)
{
dp[i][j][]=max(dp[i-][j][],dp[i-][j][])+sumY[i][j];
dp[i][j][]=max(dp[i][j-][],dp[i][j-][])+sumB[i][j];
}
}
printf("%d\n",max(dp[i-][j-][],dp[i-][j-][]));
}
return ;
}