Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- #include<algorithm>
- using namespace std;
- int main(){
- ifstream in;
- ofstream ou;
- in.open("input.txt");
- int n;
- in>>n;
- int somma=n;
- somma++;
- somma=n*somma;
- somma/=2;
- int array[somma];
- for(int i=0;i<somma;i++){
- in>>array[i];
- }
- int cont=n-1;
- int s=0;
- int z=somma-n;
- z--;
- int u;
- int v;
- while(cont>0){
- u=z+cont;
- v=z+cont;
- v++;
- if(s<cont+1){
- s++;
- if(array[u]>=array[v]){
- array[z]+=array[u];
- }
- else{
- array[z]+=array[v];
- }
- }else{
- cont--;
- s=0;
- }
- z--;
- }
- ou.open("output.txt");
- ou<<array[0];
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement