Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.001 s | 0 KBi |
#2 |
Correcto
|
0.002 s | 0 KBi |
#3 |
Correcto
|
0.004 s | 5 KBi |
#4 |
Correcto
|
0.004 s | 6 KBi |
#5 |
Correcto
|
0.004 s | 40 KBi |
#6 |
Correcto
|
0.002 s | 0 KBi |
#7 |
Correcto
|
0.005 s | 9 KBi |
#8 |
Correcto
|
0.004 s | 14 KBi |
#9 |
Correcto
|
0.001 s | 0 KBi |
#10 |
Correcto
|
0.001 s | 0 KBi |
#11 |
Correcto
|
0.002 s | 0 KBi |
#12 |
Correcto
|
0.002 s | 0 KBi |
#13 |
Correcto
|
0.001 s | 0 KBi |
#14 |
Correcto
|
0.007 s | 8 KBi |
#15 |
Correcto
|
0.002 s | 0 KBi |
#16 |
Correcto
|
0.002 s | 0 KBi |
#17 |
Correcto
|
0.002 s | 0 KBi |
#18 |
Correcto
|
0.005 s | 11 KBi |
#19 |
Correcto
|
0.002 s | 0 KBi |
#include <bits/stdc++.h> using namespace std; int arr[100]; int arr2[100]; int n; int solve(int i, int h){ if(i >= n){ return 0; } else if(h > 0 && h <= arr[i]){ return h+solve(i+1, h); }else if (h == 0){ int ans = solve(i+1, 0); for(int j = 0; j < n; j++){ if(arr2[j] > arr[i]) break; ans = max(ans, arr2[j]+solve(i+1, arr2[j])); } return ans; } return 0; } int main(){ cin >> n; for( int i = 0; i < n ; i++){ cin >> arr[i]; arr2[i] = arr[i]; } sort(arr2, arr2+n); cout << solve(0,0); }