Skip to content

Commit 0dafc60

Browse files
authored
Merge pull request #96 from YoonYn9915/main
YoonYn9915/ 11월 3주차 / 3문제
2 parents 7a3e2c3 + b11c4b1 commit 0dafc60

File tree

3 files changed

+92
-0
lines changed

3 files changed

+92
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
N = int(input())
2+
ansList = []
3+
4+
for i in range(N):
5+
days = int(input())
6+
costs = list(map(int, input().split()))
7+
ans = 0
8+
9+
maxCost = -1
10+
11+
for j in range(len(costs) - 1, -1, -1):
12+
if maxCost > costs[j]:
13+
ans += maxCost - costs[j]
14+
else:
15+
maxCost = costs[j]
16+
17+
ansList.append(ans)
18+
19+
for i in range(len(ansList)):
20+
print(f"#{i + 1} {ansList[i]}")
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
N = int(input())
2+
3+
for i in range(N):
4+
num = int(input())
5+
6+
arr = [[-1] * num for _ in range(num)]
7+
val = 1
8+
9+
row = 0
10+
col = 0
11+
12+
dx = [-1, 1, 0, 0]
13+
dy = [0, 0, -1, 1]
14+
15+
dir = 3
16+
17+
while True:
18+
19+
if val > num * num:
20+
break
21+
22+
arr[row][col] = val
23+
val += 1
24+
25+
newRow = row + dx[dir]
26+
newCol = col + dy[dir]
27+
28+
if newRow >= num or newRow < 0 or newCol >= num or newCol < 0 or arr[newRow][newCol] != -1:
29+
if dir == 0:
30+
dir = 3
31+
elif dir == 1:
32+
dir = 2
33+
elif dir == 2:
34+
dir = 0
35+
elif dir == 3:
36+
dir = 1
37+
38+
row = row + dx[dir]
39+
col = col + dy[dir]
40+
else:
41+
row = newRow
42+
col = newCol
43+
44+
print(f"#{i+1}")
45+
for j in range(num):
46+
for k in range(num):
47+
print(arr[j][k], end=" ")
48+
print()
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import sys
2+
3+
# 입력 처리
4+
N, S = map(int, sys.stdin.readline().split())
5+
arr = list(map(int, sys.stdin.readline().split()))
6+
7+
# 초기화
8+
ans = float('inf')
9+
start, end = 0, 0
10+
current_sum = 0
11+
12+
# 투 포인터로 부분합 찾기
13+
while end < N:
14+
current_sum += arr[end]
15+
end += 1
16+
17+
# 현재 합이 S 이상일 경우
18+
while current_sum >= S:
19+
ans = min(ans, end - start)
20+
current_sum -= arr[start]
21+
start += 1
22+
23+
24+
print(0 if ans == float('inf') else ans)

0 commit comments

Comments
 (0)