Guest User

Untitled

a guest
Nov 15th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. #include <cmath>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <iostream>
  5. #include <algorithm>
  6. using namespace std;
  7.  
  8.  
  9. int main() {
  10. long int N,K,p,q,sum,i,j,max=0,x=0;
  11.  
  12. cin>>N>>K;
  13. long int *a=new long int[N+1]();
  14.  
  15. for(i=0;i<K;i++)
  16. {
  17. cin>>p>>q>>sum;
  18. a[p]+=sum;
  19. if((q+1)<=N) a[q+1]-=sum;
  20. }
  21.  
  22. for(i=1;i<=N;i++)
  23. {
  24. x=x+a[i];
  25. if(max<x) max=x;
  26.  
  27. }
  28.  
  29. cout<<max;
  30. return 0;
  31. }
Add Comment
Please, Sign In to add comment