-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathArrayManipulation.java
More file actions
51 lines (36 loc) · 850 Bytes
/
ArrayManipulation.java
File metadata and controls
51 lines (36 loc) · 850 Bytes
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
43
44
45
46
47
48
49
50
51
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int m = scan.nextInt();
long[] arr = new long[n];
int lower;
int upper;
long sum;
for(int i=0;i<n;i++)
arr[i]=0;
for(int i=0;i<m;i++){
lower=scan.nextInt();
upper=scan.nextInt();
sum=scan.nextInt();
arr[lower-1]+=sum;
if(upper<n)
arr[upper]-=sum;
}
long max=0;
long temp=0;
for(int i=0;i<n;i++){
temp += arr[i];
if(temp> max)
max=temp;
}
System.out.println(max);
}
}