Advertisement
Josif_tepe

Untitled

Mar 27th, 2022
955
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3. #include <algorithm>
  4. #include <vector>
  5. #include <algorithm>
  6. #include <set>
  7. #include <cstring>
  8. #include <cmath>
  9. #include <map>
  10. #include <fstream>
  11. using namespace std;
  12. int n;
  13. int arr[505];
  14. int f(int i) {
  15.     if(i == n - 1) {
  16.         return arr[n - 1];
  17.     }
  18.     return max(f(i + 1), arr[i]);
  19. }
  20. int main() {
  21.     cin >> n;
  22.     for(int i = 0; i < n; i++) {
  23.         cin >> arr[i];
  24.     }
  25.     cout << f(0) << endl;
  26.    
  27.    return 0;
  28. }
  29. /*
  30. f(0) --> max(f(1), 9) = max(4, 9) = 9
  31. f(1) --> max(f(2), 1) = max(4, 1) = 4
  32. f(2) --> max(f(3), 2) = max(4, 2) = 4
  33. f(3) --> max(f(4), 3) = max(4, 3) = 4
  34. f(4) --> 4
  35.  
  36.  
  37.  */
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement