• + 0 comments

    my approach is also similar but i am getting segmentation fault in some test cases. please tell the problem.

    long arrayManipulation(int n, vector> queries) {

      long a[n]={0};
    for(int i=0;i<queries.size();i++)
    {
        a[queries[i][0]-1]+=queries[i][2];
        if(queries[i][1]<n)
        a[queries[i][1]]-=queries[i][2];
    }
    long ans=a[0];
    for(int i=1;i<n;i++)
    {
        a[i]+=a[i-1];
        ans=max(ans,a[i]);
    }
    return ans;
    

    }