Advertisement
heian

Untitled

Jun 10th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.  
  8. int A[]={-1, 7, 0, 7, -8};
  9. int n=5;
  10. int maxim = A[0];
  11. int nr_noduri_nivel = 1;
  12. int sol = 1, lim=1;
  13. for(int nivel=2;nivel<=32;nivel++)
  14. {
  15. nr_noduri_nivel*=2;
  16. int suma_nivel = 0;
  17. int nod;
  18. for(nod=lim+1;nod<=lim+nr_noduri_nivel;nod++)
  19. {
  20. suma_nivel+=A[nod-1];
  21. if(nod==n)
  22. {
  23. nivel = 33;
  24. break;
  25. }
  26. }
  27. lim = nod-1;
  28.  
  29. if(suma_nivel > maxim)
  30. {
  31. maxim = suma_nivel;
  32. sol = nivel;
  33. }
  34.  
  35. }
  36.  
  37.  
  38. cout<<sol<<"\n";
  39. cout<<maxim<<"\n";
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement