forked from TARANG0503/DSA-Practice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5. Array Manipulation.java
42 lines (30 loc) · 1.19 KB
/
5. Array Manipulation.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner sc=new Scanner(System.in);
long N=sc.nextLong();
long M=sc.nextLong();
long A[]=new long[(int)N+1];
for(int i=1;i<=N;i++) A[i]=0;
long max=0,sum=0;;
long a;
long b;
long k;
for(int i=1;i<=M;i++)
{
a=sc.nextLong();
b=sc.nextLong();
k=sc.nextLong();
A[(int)a]+=k;
if(b<N)A[(int)b+1]-=k;
}
for(int i=1;i<=N;i++)
{
sum+=A[i];
if(sum>max) max=sum;
}
System.out.println(max);
}
}