Skip to content

Commit

Permalink
Merge pull request #137 from AlgoLeadMe/35-pknujsp
Browse files Browse the repository at this point in the history
35-pknujsp
  • Loading branch information
pknujsp authored Mar 3, 2024
2 parents bc348cd + 7e1d50c commit 64cd3b5
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 1 deletion.
43 changes: 43 additions & 0 deletions pknujsp/BFS/33-์ด๋ถ„ ๊ทธ๋ž˜ํ”„.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from sys import *
from collections import *


def bfs(start):
q = deque([start])
groups[start] = 1

while q:
curr = q.popleft()
visited[curr] = True

for adj in graph[curr]:
if visited[adj]:
continue

if not groups[adj]:
groups[adj] = -groups[curr]
q.append(adj)
elif groups[adj] == groups[curr]:
return False
return True


for _ in range(int(stdin.readline())):
V, E = map(int, stdin.readline().split())
graph = [[] for i in range(V + 1)]

for _ in range(E):
a, b = map(int, stdin.readline().split())
graph[a].append(b)
graph[b].append(a)

groups = [0] * (V + 1)
visited = [False] * (V + 1)
result = None

for i in range(1, V + 1):
if groups[i] == 0 and not bfs(i):
result = 'NO'
break

print('YES' if not result else result)
5 changes: 4 additions & 1 deletion pknujsp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,7 @@
| 29์ฐจ์‹œ | 2024.01.18 | DFS, UNION-FIND | [์ˆœ์—ด ์‚ฌ์ดํด](https://www.acmicpc.net/problem/10451) | [#112](https://github.com/lgoLeadMe/AlgoLeadMe-1/pull/112) |
| 30์ฐจ์‹œ | 2024.01.23 | DP | [ABBC](https://www.acmicpc.net/problem/25381) | [#119](https://github.com/lgoLeadMe/AlgoLeadMe-1/pull/119) |
| 31์ฐจ์‹œ | 2024.01.30 | SORT | [๋ฉ€ํ‹ฐ๋ฒ„์Šค โ…ก](https://www.acmicpc.net/problem/18869) | [#123](https://github.com/lgoLeadMe/AlgoLeadMe-1/pull/123) |
| 32์ฐจ์‹œ | 2024.02.04 | BFS | [์ˆจ๋ฐ”๊ผญ์งˆ 3](https://www.acmicpc.net/problem/13549) | [#127](https://github.com/lgoLeadMe/AlgoLeadMe-1/pull/127) |
| 32์ฐจ์‹œ | 2024.02.04 | BFS | [์ˆจ๋ฐ”๊ผญ์งˆ 3](https://www.acmicpc.net/problem/13549) | [#127](https://github.com/lgoLeadMe/AlgoLeadMe-1/pull/127) |
| 33์ฐจ์‹œ | 2024.02.06 | ํ | [์ฒ ๋กœ](https://www.acmicpc.net/problem/13334) | [#132](https://github.com/lgoLeadMe/AlgoLeadMe-1/pull/132) |
| 34์ฐจ์‹œ | 2024.02.12 | BFS | [์ด๋ถ„ ๊ทธ๋ž˜ํ”„](https://www.acmicpc.net/problem/1707) | [#135](https://github.com/lgoLeadMe/AlgoLeadMe-1/pull/135) |
| 35์ฐจ์‹œ | 2024.02.18 | ๊ทธ๋ฆฌ๋”” | [์„ ๋ฌผํ• ์ธ](https://www.acmicpc.net/problem/25947) | [#137](https://github.com/lgoLeadMe/AlgoLeadMe-1/pull/137) |
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from sys import *

n, budget, max_sales = map(int, stdin.readline().split())
gifts = sorted(list(map(int, stdin.readline().split())))

min_price_gift = max_price_gift = 0
prices = 0
sales = 0

for sale_gift in range(max_sales):
prices += gifts[sale_gift] // 2
max_price_gift += 1

if prices > budget:
print(sale_gift)
exit()

sales = max_price_gift - min_price_gift
while max_price_gift < n:
if sales < max_sales or max_sales == 0:
if max_sales == 0:
prices += gifts[max_price_gift]
else:
prices += gifts[max_price_gift] // 2

if prices > budget:
break

max_price_gift += 1
sales += 1
else:
prices += gifts[min_price_gift] // 2
min_price_gift += 1
sales -= 1

print(max_price_gift)
28 changes: 28 additions & 0 deletions pknujsp/ํ/33-์ฒ ๋กœ.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from sys import *
from heapq import *

points = []

for _ in range(int(stdin.readline().strip())):
h, o = map(int, stdin.readline().strip().split())
points.append([min(h, o), max(h, o)])

points.sort(key=lambda x: x[1])
D = int(stdin.readline().strip())

max_users = 0
start_points_list = []

for start, destination in points:
if start + D < destination:
continue
heappush(start_points_list, start)

while start_points_list:
if start_points_list[0] + D >= destination:
break
heappop(start_points_list)

max_users = max(max_users, len(start_points_list))

print(max_users)

0 comments on commit 64cd3b5

Please sign in to comment.