-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBYTESM2.cpp
More file actions
37 lines (37 loc) · 1 KB
/
BYTESM2.cpp
File metadata and controls
37 lines (37 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>
#include <cstdlib>
#include <algorithm>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int h , m;
cin>>h>>m;
int arr[h+9][m+9];
for(int i = 0 ; i < h ; i++)
for(int j = 0 ; j < m ; j++)
cin>>arr[i][j];
int ma = -1;
for(int i = 0 ; i < m ; i++)
ma = max(ma , arr[0][i]);
for(int i = 1 ; i < h ; i++)
{
ma = -1;
for(int j = 0 ; j < m ; j++)
{
if(j>0 && j<m-1)
arr[i][j] = max(arr[i-1][j] + arr[i][j] , max(arr[i-1][j-1]+arr[i][j] , arr[i-1][j+1]+arr[i][j]));
else if(j>0)
arr[i][j] = max(arr[i-1][j]+arr[i][j] ,arr[i-1][j-1]+arr[i][j]);
else if(j<m-1)
arr[i][j] = max(arr[i-1][j]+arr[i][j],arr[i-1][j+1]+arr[i][j]);
ma = max(arr[i][j] , ma);
}
}
cout<<ma<<endl;
}
return 0;
}