Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.001 s | 0 KBi |
#2 |
Correcto
|
0.001 s | 0 KBi |
#3 |
Correcto
|
0.001 s | 0 KBi |
#4 |
Correcto
|
0.006 s | 63 KBi |
#5 |
Correcto
|
0.003 s | 6 KBi |
#6 |
Correcto
|
0.002 s | 0 KBi |
#7 |
Correcto
|
0.002 s | 0 KBi |
#8 |
Correcto
|
0.002 s | 0 KBi |
#9 |
Correcto
|
0.002 s | 0 KBi |
#10 |
Correcto
|
0.002 s | 0 KBi |
#11 |
Correcto
|
0.001 s | 0 KBi |
#12 |
Correcto
|
0.002 s | 0 KBi |
#13 |
Correcto
|
0.001 s | 0 KBi |
#14 |
Tiempo límite excedido
|
1.049 s | 7 KBi |
#15 |
Correcto
|
0.005 s | 20 KBi |
#16 |
Correcto
|
0.049 s | 0 KBi |
#17 |
Correcto
|
0.727 s | 0 KBi |
#18 |
Correcto
|
0.001 s | 0 KBi |
#19 |
Correcto
|
0.004 s | 35 KBi |
#include <bits/stdc++.h> using namespace std; int arr[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 = 0; for(int j = 0; j <= arr[i]; j++){ ans = max(ans, j+solve(i+1, j)); } return ans; } return 0; } int main(){ cin >> n; for( int i = 0; i < n ; i++){ cin >> arr[i]; } cout << solve(0,0); }