-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #143 from AlgoLeadMe/36-pknujsp
36 pknujsp
- Loading branch information
Showing
5 changed files
with
154 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
N, M, L = map(int, input().split()) | ||
array = list(map(int, input().split())) | ||
array.sort() | ||
|
||
left = 1 | ||
right = L - 1 | ||
|
||
min_max_distance = right | ||
|
||
while left <= right: | ||
max_distance = (left + right) // 2 | ||
extra_added = 0 | ||
last_installed_x = 0 | ||
|
||
for installed_x in array: | ||
if installed_x - last_installed_x > max_distance: | ||
extra_added += (installed_x - last_installed_x - 1) // max_distance | ||
|
||
last_installed_x = installed_x | ||
|
||
if L - last_installed_x > max_distance: | ||
extra_added += (L - last_installed_x - 1) // max_distance | ||
|
||
if extra_added > M: | ||
left = max_distance + 1 | ||
else: | ||
right = max_distance - 1 | ||
|
||
print(left) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |