2021-11-19 09:01:13 +00:00
|
|
|
#include <bits/stdc++.h>
|
2020-10-26 13:39:24 +00:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
int n, a[1005][1005], f[1005][1005];
|
|
|
|
cin >> n;
|
2021-11-19 09:01:13 +00:00
|
|
|
for (int i = 1; i <= n; i++) {
|
|
|
|
for (int j = 1; j <= i; j++) {
|
2020-10-26 13:39:24 +00:00
|
|
|
cin >> a[i][j];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
f[1][1] = a[1][1];
|
2021-11-19 09:01:13 +00:00
|
|
|
for (int i = 1; i <= n; i++) {
|
|
|
|
for (int j = 1; j <= i + 1; j++) {
|
|
|
|
f[i][j] = a[i][j] + max(f[i - 1][j], f[i - 1][j - 1]);
|
2020-10-26 13:39:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
int ans = -0x3f3f3f;
|
2021-11-19 09:01:13 +00:00
|
|
|
for (int i = 1; i <= n; i++) {
|
2020-10-26 13:39:24 +00:00
|
|
|
ans = max(ans, f[n][i]);
|
|
|
|
}
|
|
|
|
cout << ans << endl;
|
|
|
|
return 0;
|
|
|
|
}
|