Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <bits/stdc++.h>
- using namespace std;
- int maxx = 0;
- int a[1000];
- int n;
- int f(int x,int cursum) {
- maxx= max(maxx,cursum);
- for (int i = x+1; i < n;i++) {
- if (a[x] < a[i]) {
- f(i,cursum+a[i]);
- }
- }
- }
- int main() {
- ios::sync_with_stdio(false);
- cout << fixed << setprecision(100);
- cin >> n;
- for (int i = 0; i < n;i++) cin >> a[i];
- int lastmax = 0;
- for (int i = 0; i < n;i++) {
- if (a[lastmax] >= a[i]) {
- f(i,a[i]);
- } else lastmax = i;
- }
- cout << maxx;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement