-
-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathArrayManipulation.java
More file actions
32 lines (30 loc) · 767 Bytes
/
Copy pathArrayManipulation.java
File metadata and controls
32 lines (30 loc) · 767 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
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int m = in.nextInt();
int[] c = new int[n];
for(int a0 = 0; a0 < m; a0++){
int a = in.nextInt()-1;
int b = in.nextInt()-1;
int k = in.nextInt();
c[a] += k;
if(b<n-1) c[b+1] -= k;
}
in.close();
long max = 0;
long sum = 0;
for(int i=0;i<n;i++){
sum += (long)c[i];
if(sum > max){
max = sum;
}
}
System.out.println(max);
}
}