Advertisement
Guest User

Untitled

a guest
Nov 11th, 2018
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. #include<algorithm>
  4. using namespace std;
  5. int main(){
  6. ifstream in;
  7. ofstream ou;
  8. in.open("input.txt");
  9. int n;
  10. in>>n;
  11. int somma=n;
  12. somma++;
  13. somma=n*somma;
  14. somma/=2;
  15. int array[somma];
  16. for(int i=0;i<somma;i++){
  17. in>>array[i];
  18. }
  19. int cont=n-1;
  20. int s=0;
  21. int z=somma-n;
  22. z--;
  23. int u;
  24. int v;
  25. while(cont>0){
  26. u=z+cont;
  27. v=z+cont;
  28. v++;
  29. if(s<cont+1){
  30. s++;
  31. if(array[u]>=array[v]){
  32. array[z]+=array[u];
  33. }
  34. else{
  35. array[z]+=array[v];
  36. }
  37. }else{
  38. cont--;
  39. s=0;
  40. }
  41. z--;
  42. }
  43. ou.open("output.txt");
  44. ou<<array[0];
  45. return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement