fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // your code goes here
  13. long k,q,s=0;
  14. int n,a,b,i;
  15. Scanner sc = new Scanner(System.in);
  16. n = sc.nextInt();
  17. q = sc.nextLong();
  18. long[] arr = new long[n+2];
  19.  
  20. for(i=0;i<q;i++){
  21. a = sc.nextInt();
  22. b = sc.nextInt();
  23. k = sc.nextLong();
  24. arr[a] = arr[a] + k;
  25. arr[b+1] = arr[b+1] - k;
  26. }
  27. long max = Integer.MIN_VALUE;
  28. for(i=1;i<=n;i++){
  29. arr[i] = arr[i] + arr[i-1];
  30. max = Math.max(arr[i],max);
  31. }
  32. System.out.print(max);
  33. }
  34. }
Success #stdin #stdout 0.09s 35332KB
stdin
5 3
1 2 100
2 5 100
3 4 100
stdout
200