-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTurtle.cpp
More file actions
37 lines (36 loc) · 710 Bytes
/
Copy pathTurtle.cpp
File metadata and controls
37 lines (36 loc) · 710 Bytes
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
// https://basecamp.eolymp.com/en/problems/8360
#include <bits/stdc++.h>
using namespace std;
const int up = 1003;
int dp[up][up];
int main()
{
int n, m, i, j;
cin >> n >> m;
for (i = 1; i <= n; i++)
for (j = 1; j <= m; j++)
cin >> dp[i][j];
for (i = 2; i <= n; i++)
for (j = 1; j <= m; j++)
dp[i][j] += max(dp[i - 1][j - 1], max(dp[i - 1][j], dp[i - 1][j + 1]));
int res = dp[n][1];
int pos = 1;
for (i = 2; i <= m; i++)
{
if (dp[n][i] > res)
{
res = dp[n][i];
pos = i;
}
}
for (i = n - 1; i >= 1; i--)
{
int best = pos - 1;
if (dp[i][pos] > dp[i][best])
best = pos;
if (dp[i][pos + 1] > dp[i][best])
best = pos + 1;
pos = best;
}
cout << pos << " " << res;
}