Skip to content

Commit d2e88ea

Browse files
authored
Merge pull request #1168 from AlgorithmWithGod/Seol-JY
[20251019] BOJ / G5 / 태상이의 훈련소 생활 / 설진영
2 parents d9833c5 + acfdb0c commit d2e88ea

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
```

0 commit comments

Comments
 (0)