Advertisement
erek1e

IOI '94 P1 - The Triangle

Jun 5th, 2022
871
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     int n; cin >> n;
  9.     vector<int> mx(1);
  10.     for (int i = 1; i <= n; ++i) {
  11.         vector<int> mx2(n);
  12.         for (int j = 0; j < i; ++j) {
  13.             int x; cin >> x;
  14.             if (j) mx2[j] = max(mx2[j], mx[j-1]);
  15.             if (j!=i-1) mx2[j] = max(mx2[j], mx[j]);
  16.             mx2[j] += x;
  17.         }
  18.         mx = mx2;
  19.     }
  20.     cout << *max_element(mx.begin(), mx.end()) << endl;
  21.     return 0;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement