fork download
  1. #include <bits/stdc++.h>
  2. #define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  3. using namespace std;
  4.  
  5. void right_max(vector<int>& arr, int idx) {
  6. if (idx < 0) return;
  7. arr[idx] = (idx == arr.size()-1) ? arr[idx] : max(arr[idx + 1],arr[idx]);
  8. right_max(arr, idx - 1);
  9. }
  10.  
  11. void solve() {
  12. vector<int> arr = {1,8,2,10,3};
  13. right_max(arr,arr.size()-1);
  14. for (auto &i : arr) cout << i << " ";
  15. }
  16.  
  17. int main() {
  18. IOS;
  19. solve();
  20. return 0;
  21. }
Success #stdin #stdout 0s 5304KB
stdin
Standard input is empty
stdout
10 10 10 10 3