Skip to content

[정] 6주차 과제 제출 #269

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions 6주차/14938/14938_python_정.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import sys

input = sys.stdin.readline

n, max_move, r = map(int, input().split())
items = [0] + list(map(int, input().split()))

route = {}
for i in range(1, n+1):
route[i] = []

# DFS solution
for _ in range(r):
a, b, l = map(int, input().split())
route[a].append((l, b))
route[b].append((l, a))

def dfs(cur_pos, moved):
global visited
for (length, next_pos) in route[cur_pos]:
total_move = moved + length
if total_move > max_move:
continue
visited[next_pos] = True
dfs(next_pos, total_move)

max_count = 0
for start in range(1, n+1):
visited = [False] * (n+1)
visited[start] = True
dfs(start, 0)
count = 0
for idx in range(1, n+1):
if visited[idx]:
count += items[idx]
max_count = max(count, max_count)

print(max_count)
43 changes: 43 additions & 0 deletions 6주차/24229/24229_python_정.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import sys

input = sys.stdin.readline

N = int(input())

roads = []

for _ in range(N):
a, b = map(int, input().split())
roads.append((a, b))

roads.sort()

connections = []
cur_start = -1
cur_max = -1
for idx in range(N):
(a, b) = roads[idx]
if cur_start == -1:
cur_start = a
cur_max = b
if b <= cur_max: continue
if a <= cur_max and cur_max <= b:
cur_max = b
continue
connections.append((cur_start, cur_max))
cur_start = a
cur_max = b

connections.append((cur_start, cur_max))

max_jumpable = 0
max_reached = 0

for (left, right) in connections:
if max_jumpable < left: break

max_jump_length = right - left
max_jumpable = max(max_jumpable, right + max_jump_length)
max_reached = max(max_reached, right)

print(max_reached)
41 changes: 41 additions & 0 deletions 6주차/24393/24393_python_정.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import sys

input = sys.stdin.readline

n = int(input())

def get_initial_shuffle_result(joker):
(_, joker_idx) = joker
if joker_idx < 13:
return (-1, joker_idx)
return (1, joker_idx - 13)

joker = (0, 0) # left: (-1, idx) / right: (1, idx)

for i in range(n):
nums = list(map(int, input().split()))
joker = get_initial_shuffle_result(joker)
result = 0

for idx in range(len(nums)):
(pos, joker_idx) = joker
if pos == 0:
continue

num = nums[idx]
if pos == 1 and idx%2 == 0:
if joker_idx + 1 <= num:
joker = (0, result + joker_idx)
continue
joker = (pos, joker_idx - num)
if pos == -1 and idx%2 == 1:
if joker_idx + 1 <= num:
joker = (0, result + joker_idx)
continue
joker = (pos, joker_idx - num)
result += num

(pos, joker_idx) = joker

print(joker_idx + 1)

27 changes: 27 additions & 0 deletions 6주차/25391/25391_python_정.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import sys, heapq

input = sys.stdin.readline

N, M, K = map(int, input().split())

heap = []

for _ in range(N):
a, b = map(int, input().split())
heapq.heappush(heap, (-b, a))

sum = 0

for _ in range(K):
(_, a) = heapq.heappop(heap)
sum += a

new_heap = []
for _ in range(N - K):
(b, a) = heapq.heappop(heap)
heapq.heappush(new_heap, -a)

for _ in range(M):
sum -= heapq.heappop(new_heap)

print(sum)