2021-12-27 13:19:36 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <limits>
|
2020-10-26 13:39:24 +00:00
|
|
|
|
2021-12-27 13:19:36 +00:00
|
|
|
using std::cin;
|
|
|
|
using std::cout;
|
|
|
|
using std::endl;
|
|
|
|
|
|
|
|
const int N = 1005;
|
|
|
|
|
|
|
|
int r, g[N][N], f[N][N], ans = std::numeric_limits<int>::min();
|
2020-10-26 13:39:24 +00:00
|
|
|
|
|
|
|
int main() {
|
2021-12-27 13:19:36 +00:00
|
|
|
cin >> r;
|
|
|
|
for (int i = 1; i <= r; i++) {
|
2021-11-19 09:01:13 +00:00
|
|
|
for (int j = 1; j <= i; j++) {
|
2021-12-27 13:19:36 +00:00
|
|
|
cin >> g[i][j];
|
2020-10-26 13:39:24 +00:00
|
|
|
}
|
|
|
|
}
|
2021-12-27 13:19:36 +00:00
|
|
|
f[1][1] = g[1][1];
|
|
|
|
for (int i = 1; i <= r; i++) {
|
2021-11-19 09:01:13 +00:00
|
|
|
for (int j = 1; j <= i + 1; j++) {
|
2021-12-27 13:19:36 +00:00
|
|
|
f[i][j] = std::max(f[i - 1][j - 1], f[i - 1][j]) + g[i][j];
|
2020-10-26 13:39:24 +00:00
|
|
|
}
|
|
|
|
}
|
2021-12-27 13:19:36 +00:00
|
|
|
for (int i = 1; i <= r; i++) {
|
|
|
|
ans = std::max(ans, f[r][i]);
|
2020-10-26 13:39:24 +00:00
|
|
|
}
|
|
|
|
cout << ans << endl;
|
|
|
|
return 0;
|
|
|
|
}
|