File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed
Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change 1+ ```java
2+ import java.io.*;
3+ import java.util.*;
4+
5+ public class Main {
6+ public static void main(String[] args) throws IOException {
7+ BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+ StringTokenizer st = new StringTokenizer(br.readLine());
9+
10+ int N = nextInt(st);
11+ int M = nextInt(st);
12+
13+ int[] height = new int[N + 1];
14+ st = new StringTokenizer(br.readLine());
15+ for (int i = 1; i <= N; i++) {
16+ height[i] = nextInt(st);
17+ }
18+
19+ int[] diff = new int[N + 2];
20+ for (int i = 0; i < M; i++) {
21+ st = new StringTokenizer(br.readLine());
22+ int a = nextInt(st);
23+ int b = nextInt(st);
24+ int k = nextInt(st);
25+
26+ diff[a] += k;
27+ diff[b + 1] -= k;
28+ }
29+
30+ StringBuilder sb = new StringBuilder();
31+ int cumSum = 0;
32+ for (int i = 1; i <= N; i++) {
33+ cumSum += diff[i];
34+ sb.append(height[i] + cumSum).append(' ');
35+ }
36+
37+ System.out.println(sb);
38+ }
39+
40+ static int nextInt(StringTokenizer st) {
41+ return Integer.parseInt(st.nextToken());
42+ }
43+ }
44+ ```
You can’t perform that action at this time.
0 commit comments