• + 0 comments

    thanks for the logic:

    long arrayManipulation(int n, vector<vector<int>> queries) {
    // the boundary extended by 2 since 0 th position is not used.
    vector<long int> map_vector (n+2,0); 
    long int max_value = 0, moving_sum = 0;
    for(auto rows : queries)
    {
        map_vector[rows[0]] += rows[2];
        map_vector[rows[1]+1] -= rows[2];
    }
    for(auto iter: map_vector)
    {
        moving_sum += iter;
        if(max_value < moving_sum)
            max_value = moving_sum; 
    }
    return max_value;
    }