Skip to content

Commit e7f0c35

Browse files
Merge pull request #737 from baekhangyeol/main
[백한결] 119차 라이브 코테 제출
2 parents d2d90e3 + 20dff3e commit e7f0c35

2 files changed

Lines changed: 70 additions & 0 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import heapq
2+
import sys
3+
from collections import defaultdict
4+
5+
6+
def main():
7+
input = sys.stdin.readline
8+
9+
N, M = map(int, input().split())
10+
11+
problems = defaultdict(list)
12+
aheadResolveProblems = [0] * (N+1)
13+
14+
for i in range(M):
15+
A, B = map(int, input().split())
16+
problems[A].append(B)
17+
aheadResolveProblems[B] += 1
18+
19+
result = []
20+
heap = []
21+
22+
for i in range(1, N+1):
23+
if aheadResolveProblems[i] == 0:
24+
heapq.heappush(heap, i)
25+
26+
while heap:
27+
now = heapq.heappop(heap)
28+
result.append(now)
29+
30+
for next in problems[now]:
31+
aheadResolveProblems[next] -= 1
32+
if aheadResolveProblems[next] == 0:
33+
heapq.heappush(heap, next)
34+
35+
print(*result)
36+
37+
if __name__ == '__main__':
38+
main()
39+
40+
# 1234
41+
# 1. 4는 2보다 먼저 푸는 것이 좋음 -> 1 4 2 3
42+
# 2. 3은 1보다 먼저 푸는 것이 좋음 -> 3 1 4 2
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import sys
2+
3+
def main():
4+
input = sys.stdin.readline
5+
6+
N, S = map(int, input().split())
7+
sequence = list(map(int, input().split()))
8+
9+
start = 0
10+
end = 0
11+
current_sum = 0
12+
result = float('inf')
13+
14+
while True:
15+
if current_sum >= S:
16+
result = min(result, end - start)
17+
current_sum -= sequence[start]
18+
start += 1
19+
elif end == N:
20+
break
21+
else:
22+
current_sum += sequence[end]
23+
end += 1
24+
25+
print(result if result != float('inf') else 0)
26+
27+
if __name__ == '__main__':
28+
main()

0 commit comments

Comments
 (0)