Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int A[]={-1, 7, 0, 7, -8};
- int n=5;
- int maxim = A[0];
- int nr_noduri_nivel = 1;
- int sol = 1, lim=1;
- for(int nivel=2;nivel<=32;nivel++)
- {
- nr_noduri_nivel*=2;
- int suma_nivel = 0;
- int nod;
- for(nod=lim+1;nod<=lim+nr_noduri_nivel;nod++)
- {
- suma_nivel+=A[nod-1];
- if(nod==n)
- {
- nivel = 33;
- break;
- }
- }
- lim = nod-1;
- if(suma_nivel > maxim)
- {
- maxim = suma_nivel;
- sol = nivel;
- }
- }
- cout<<sol<<"\n";
- cout<<maxim<<"\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement