Language: C++

#include  <iostream>
#include  <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;


#include <math.h>
int standerd = int(pow(10.0,9.0)) + 7;

string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

class SegmentTree {
private:
    int n;
    vector<int> node;

    int segmentValue(int left_node,int right_node){
        return min(left_node,right_node);
    }

public:
    int getLeftChildNode(int now_index){
        return node[getLeftChildIndex(now_index)];
    }
    int getRightChildNode(int now_index){
        return node[getRightChildIndex(now_index)];
    }
    int getLeftChildIndex(int now_index){
        return now_index * 2 + 1;
    }
    int getRightChildIndex(int now_index){
        return now_index * 2 + 2;
    }
    int getParentIndex(int now_index){
        int index = (n - 1) / 2;
        return index;
    }
    // 元配列 v をセグメント木で表現する
    reBottomUpCalculate(){
        for(int i=n-2; i>=0; i--) node[i] =segmentValue(node[2*i+1], node[2*i+2]);
    }
    bool isLeafIndex(int now_index){
        if(now_index >= node.size()) return false;
        else if (now_index <= n-2 ) return false;
        else return true;        
    }

    SegmentTree(vector<int> v) {
        // 最下段のノード数は元配列のサイズ以上になる最小の 2 冪 -> これを n とおく
        // セグメント木全体で必要なノード数は 2n-1 個である
        int sz = v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1, 0);

        // 最下段に値を入れたあとに、下の段から順番に値を入れる
        // 値を入れるには、自分の子の 2 値を参照すれば良い
        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] =segmentValue(node[2*i+1], node[2*i+2]);
    }
    int breadthFirstSearch(int value){
        for( int ni = 0 ; ni < node.size() ; ni++ ){
            if(node[ni]==value) return ni;
        }
        return node.size();
    }
    int breadthFirstSearchGE(int value){
        for( int ni = 0 ; ni < node.size() ; ni++ ){
            if(node[ni]>=value) return ni;
        }
        return node.size();
    }
    int getNodeSize(){
        return node.size();
    }
    inputValueToChild(int now_index,int value){
        if(isLeafIndex(now_index)) node[now_index] = value;
        else{
            inputValueToChild(getLeftChildIndex(now_index),value);
            inputValueToChild(getRightChildIndex(now_index),value);
        }
    }
    calculateValueToChild(int now_index,int value){
        if(isLeafIndex(now_index)) node[now_index] = node[now_index] - value;
        else{
            calculateValueToChild(getLeftChildIndex(now_index),value);
            calculateValueToChild(getRightChildIndex(now_index),value);
        }
    }
    bool calculate(){
        int right_max_index = 0;
        int count = 0;
        int stage = 0;
        int index = 0;
        while(right_max_index < node.size()){
            index = breadthFirstSearchGE(1);
            cout << "index "<<   index << endl;
            while(index <= right_max_index){
                int index2 = index + 1;
                int min_value = node[index];
                while(node[index2] > 0 && index2 <= right_max_index){
                    min_value = min(min_value,node[index2]);
                    index2++;
                }
                while(node[index] > 0 && index <= right_max_index){
                    calculateValueToChild(index,min_value);
                    index++;
                }
                count = count + min_value;
                reBottomUpCalculate();
                index = breadthFirstSearchGE(1);
                cout << "count " << count << endl;
                showAllNodes();
            }
            stage++;
            right_max_index = (pow(2,stage+1) - 1) - 1;
        }
        cout << count;
    }

    showAllNodes(){
        for( int ni = 0 ; ni < node.size() ; ni++ ){
            cout << " " << ni << ":" << node[ni] << endl;
        }
    }

};

int main(){

    int N;
    cin >> N;
    vector<int> flower;
    int value;
    for( int ni = 0 ; ni < N ; ni++ ){
        cin >> value;
        flower.push_back(value);
    }

    int left=0;
    int right=0;
    int min_val;
    int count = 0;
    while( left < N){
        right = left;
        while(right+1<N && flower[right+1]>0){
            right++;
        }
        min_val = flower[left];

        for( int index = left + 1 ; index <= right ; index++ ){
            if(min_val > flower[index]) min_val = flower[index];
        }
        count = count + min_val;

        cout << "count " << count << endl;
        cout << "l:" << left << "  r:" << right << endl;
        for( int index = left ; index <= right ; index++ ){
            flower[index] = flower[index] - min_val;
        }

        for( int index = 0 ; index < N ; index++ ){
            cout << flower[index] << " ";
        }
        cout << endl;

        while(left<N && flower[left]==0){
            left++;
        }
        

    }


}

Compiler output:
a.cc:43:5: error: ISO C++ forbids declaration of 'reBottomUpCalculate' with no type [-fpermissive]
   43 |     reBottomUpCalculate(){
      |     ^~~~~~~~~~~~~~~~~~~
a.cc:79:5: error: ISO C++ forbids declaration of 'inputValueToChild' with no type [-fpermissive]
   79 |     inputValueToChild(int now_index,int value){
      |     ^~~~~~~~~~~~~~~~~
a.cc:86:5: error: ISO C++ forbids declaration of 'calculateValueToChild' with no type [-fpermissive]
   86 |     calculateValueToChild(int now_index,int value){
      |     ^~~~~~~~~~~~~~~~~~~~~
a.cc:124:5: error: ISO C++ forbids declaration of 'showAllNodes' with no type [-fpermissive]
  124 |     showAllNodes(){
      |     ^~~~~~~~~~~~
a.cc: In member function 'int SegmentTree::reBottomUpCalculate()':
a.cc:45:5: warning: no return statement in function returning non-void [-Wreturn-type]
   45 |     }
      |     ^
a.cc: In member function 'int SegmentTree::inputValueToChild(int, int)':
a.cc:85:5: warning: no return statement in function returning non-void [-Wreturn-type]
   85 |     }
      |     ^
a.cc: In member function 'int SegmentTree::calculateValueToChild(int, int)':
a.cc:92:5: warning: no return statement in function returning non-void [-Wreturn-type]
   92 |     }
      |     ^
a.cc: In member function 'bool SegmentTree::calculate()':
a.cc:122:5: warning: no return statement in function returning non-void [-Wreturn-type]
  122 |     }
      |     ^
a.cc: In member function 'int SegmentTree::showAllNodes()':
a.cc:128:5: warning: no return statement in function returning non-void [-Wreturn-type]
  128 |     }
      |     ^