Skip to content

Commit 98d3594

Browse files
Merge pull request #743 from gmlrude/main
[박희경] 122차 라이브 코테 제출
2 parents 526e05c + ab8502b commit 98d3594

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import sys
2+
3+
input = sys.stdin.readline
4+
5+
n, m = map(int, input().split())
6+
area = []
7+
for _ in range(n):
8+
area.append(list(map(int, input().split())))
9+
10+
prefix_sum = [[0] * (m + 1) for _ in range(n + 1)]
11+
for i in range(1, n + 1):
12+
for j in range(1, m + 1):
13+
prefix_sum[i][j] = prefix_sum[i-1][j] + prefix_sum[i][j-1] - prefix_sum[i-1][j-1] + area[i-1][j-1]
14+
15+
k = int(input())
16+
for _ in range(k):
17+
x1, y1, x2, y2 = map(int, input().split())
18+
result = prefix_sum[x2][y2] - prefix_sum[x1 - 1][y2] - prefix_sum[x2][y1 - 1] + prefix_sum[x1-1][y1-1]
19+
print(result)
20+
21+
"""
22+
4 4
23+
9 14 29 7
24+
1 31 6 13
25+
21 26 40 16
26+
8 38 11 23
27+
3
28+
1 1 3 2
29+
1 1 1 4
30+
1 1 4 4
31+
"""
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import sys
2+
3+
input = sys.stdin.readline
4+
5+
n = int(input())
6+
k = int(input())
7+
sensor = list(map(int, input().split()))
8+
sensor.sort()
9+
10+
res, cnt = 0, 1
11+
for i in range(n):
12+
if i % 2 != 0:
13+
if i == n - 1: abs(sensor[i] - sensor[i-1])
14+
else:
15+
res += min(abs(sensor[i] - sensor[i-1]), abs(sensor[i+1] - sensor[i]))
16+
else:
17+
if cnt < k:
18+
cnt += 1
19+
20+
print(res)

0 commit comments

Comments
 (0)