Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- pytorch
- GCP
- vscode
- Matplotlib
- python
- FDS
- 백준
- NaverAItech
- Kaggle
- leetcode
- FastAPI
- github
- GIT
- pep8
- torchserve
- 프로그래머스
- wandb
- docker
- autoencoder
- rnn
- 네이버AItech
- 완전탐색
- PytorchLightning
- GitHub Action
- datascience
- DeepLearning
- 알고리즘
- NLP
- 코딩테스트
- Kubernetes
Archives
- Today
- Total
Sangmun
백준 17976번 Thread knots 본문
17976번: Thread Knots (acmicpc.net)
17976번: Thread Knots
Your program is to read from standard input. The input starts with a line containing one integer, n (2 ≤ n ≤ 100,000), where n is the number of threads. In the following n lines, the i-th line contains two integers xi (0 ≤ xi ≤ 109) and li (1 ≤
www.acmicpc.net
* 이분 탐색으로 풀이하는 문제
import sys
input = sys.stdin.readline
n = int(input())
lines = []
for _ in range(n):
a,b = map(int,input().split())
lines.append((a,b))
lines.sort()
def search(x):
before = lines[0][0]
for each in lines[1:]:
now = each[0]
if now - before < x:
tmp = before + x
if each[0] <= tmp <= each[0] + each[1]:
before = tmp
else:
return False
else:
before = now
return True
start = 0
end = 2000000000
while start <= end:
mid = (start + end) // 2
result = search(mid)
# 이분탐색으로 문제 풀이
if result:
start = mid + 1
else:
end = mid - 1
if result: print(mid)
else: print(mid-1)
'알고리즘 > 백준' 카테고리의 다른 글
백준 1495번 기타리스트 (0) | 2023.02.06 |
---|---|
백준 7490번 0 만들기 (0) | 2023.02.04 |
백준 1449번 수리공 (0) | 2023.02.03 |
백준 1049번 기타줄 (0) | 2023.02.03 |
백준 11057 오르막 수 (0) | 2022.12.22 |
Comments