Skip to content

Instantly share code, notes, and snippets.

@gabrielepalma
Created November 15, 2018 18:46
Show Gist options
  • Save gabrielepalma/de8caf951f67beacb18fe5917da8de61 to your computer and use it in GitHub Desktop.
Save gabrielepalma/de8caf951f67beacb18fe5917da8de61 to your computer and use it in GitHub Desktop.
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
long int N,K,p,q,sum,i,j,max=0,x=0;
cin>>N>>K;
long int *a=new long int[N+1]();
for(i=0;i<K;i++)
{
cin>>p>>q>>sum;
a[p]+=sum;
if((q+1)<=N) a[q+1]-=sum;
}
for(i=1;i<=N;i++)
{
x=x+a[i];
if(max<x) max=x;
}
cout<<max;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment