BYTESM2 - Philosophers Stone
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int t, h, w, m, temp;
cin >> t;
while(t--)
{
cin >> h >> w;
m = 0;
temp = 0;
int arr[h][w];
for(int i = 0; i < h; i++)
{
for(int j = 0; j < w; j++)
{
cin >> arr[i][j];
}
}
for(int i = 1; i < h; i++)
{
for(int j = 0; j < w; j++)
{
temp = arr[i - 1][j];
if(j > 0)
{
temp = max(temp, arr[i - 1][j - 1]);
}
if(j < w - 1)
{
temp = max(temp, arr[i - 1][j + 1]);
}
arr[i][j] += temp;
}
}
for(int i = 0; i < w; i++)
{
if(arr[h - 1][i] > m)
m = arr[h - 1][i];
}
cout << m << endl;
}
return 0;
}
Comments
Post a Comment