Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- int main() {
- int n; cin >> n;
- vector<int> mx(1);
- for (int i = 1; i <= n; ++i) {
- vector<int> mx2(n);
- for (int j = 0; j < i; ++j) {
- int x; cin >> x;
- if (j) mx2[j] = max(mx2[j], mx[j-1]);
- if (j!=i-1) mx2[j] = max(mx2[j], mx[j]);
- mx2[j] += x;
- }
- mx = mx2;
- }
- cout << *max_element(mx.begin(), mx.end()) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment