You are viewing a single comment's thread. Return to all comments →
I used the same approach but I am getting a segmentation fault in test cases 7-12. Can someone please explain me why?
#include<iostream> using namespace std; int main() { long n,m,a,b,k,sum=0,ans=0; cin>>n>>m; long int arr[n+1]={0}; for(int i=0;i<m;i++) { cin>>a>>b>>k; arr[a]+=k; if(b!=n) arr[b+1]-=k; } for(int i=1;i<=n;i++) { sum+=arr[i]; if(sum>ans) ans=sum; } cout<<ans<<endl; }
Seems like cookies are disabled on this browser, please enable them to open this website
Array Manipulation
You are viewing a single comment's thread. Return to all comments →
I used the same approach but I am getting a segmentation fault in test cases 7-12. Can someone please explain me why?