Advertisement
Guest User

Untitled

a guest
Dec 15th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5. int maxx = 0;
  6. int a[1000];
  7. int n;
  8. int f(int x,int cursum) {
  9. maxx= max(maxx,cursum);
  10. for (int i = x+1; i < n;i++) {
  11. if (a[x] < a[i]) {
  12. f(i,cursum+a[i]);
  13. }
  14. }
  15. }
  16. int main() {
  17. ios::sync_with_stdio(false);
  18. cout << fixed << setprecision(100);
  19. cin >> n;
  20. for (int i = 0; i < n;i++) cin >> a[i];
  21. int lastmax = 0;
  22. for (int i = 0; i < n;i++) {
  23. if (a[lastmax] >= a[i]) {
  24. f(i,a[i]);
  25. } else lastmax = i;
  26. }
  27. cout << maxx;
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement