Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- #include <algorithm>
- #include <vector>
- #include <algorithm>
- #include <set>
- #include <cstring>
- #include <cmath>
- #include <map>
- #include <fstream>
- using namespace std;
- int n;
- int arr[505];
- int f(int i) {
- if(i == n - 1) {
- return arr[n - 1];
- }
- return max(f(i + 1), arr[i]);
- }
- int main() {
- cin >> n;
- for(int i = 0; i < n; i++) {
- cin >> arr[i];
- }
- cout << f(0) << endl;
- return 0;
- }
- /*
- f(0) --> max(f(1), 9) = max(4, 9) = 9
- f(1) --> max(f(2), 1) = max(4, 1) = 4
- f(2) --> max(f(3), 2) = max(4, 2) = 4
- f(3) --> max(f(4), 3) = max(4, 3) = 4
- f(4) --> 4
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement