Created
August 1, 2021 14:47
-
-
Save uchidama/bbbabd7d49d7ea6a36fdda0398ad64de to your computer and use it in GitHub Desktop.
AtCoder Beginner Contest 212 [ C - Min Difference ] https://atcoder.jp/contests/abc212/tasks/abc212_c
This file contains hidden or 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
| ''' | |
| [問題] | |
| https://atcoder.jp/contests/abc212/tasks/abc212_c | |
| [結果] | |
| PyPy3(7.3.0) AC 243ms | |
| Python(3.8.2) AC 423ms | |
| ''' | |
| import sys | |
| import bisect | |
| sys.setrecursionlimit(10 ** 6) # 再帰上限の引き上げ | |
| input = sys.stdin.readline | |
| INF = 2 ** 63 - 1 | |
| N, M = map(int, input().split()) | |
| A = list(map(int, input().split())) | |
| B = list(map(int, input().split())) | |
| A.sort() | |
| B.sort() | |
| ans = INF | |
| for a in A: | |
| # Bから二分探索で近い数字を探す | |
| i = bisect.bisect_right(B, a) | |
| min_a = abs(a - B[i-1]) | |
| if (len(B) - 1) >= i: | |
| # B[i]の値とも比較しとく | |
| min_a = min( min_a, abs(a - B[i])) | |
| # min_aが最小値ならansへ | |
| ans = min(ans, min_a) | |
| print(ans) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment