We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
while(m--){
int a,b,c;
cin>>a>>b>>c;
// prefix sum concept
arr[a] += c;
arr[b+1] -=c;
}
for(int i =1;i<=n;i++){
arr[i] += arr[i-1];
}
long long max = -1;
for(int i =1;i<=n;i++){
if(max<arr[i]){
max = arr[i];
}
}
cout<<max<<endl;
return 0;
Array Manipulation
You are viewing a single comment's thread. Return to all comments →
In cpp -:
include
using namespace std;
const int N = 1e7+10; long long arr[N];
int main(){ int n,m; cin>>n>>m;
}