結果
| 問題 |
No.1597 Matrix Sort
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 13:24:49 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 1,386 ms / 1,500 ms |
| コード長 | 827 bytes |
| コンパイル時間 | 237 ms |
| コンパイル使用メモリ | 82,176 KB |
| 実行使用メモリ | 105,060 KB |
| 最終ジャッジ日時 | 2025-06-12 13:30:36 |
| 合計ジャッジ時間 | 25,898 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
import bisect
n, k, p = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.sort()
B.sort()
low = 0
high = p - 1
ans = -1
while low <= high:
mid = (low + high) // 2
part1 = 0
j = n - 1 # B is sorted in ascending order
for a in A:
while j >= 0 and (a + B[j]) > mid:
j -= 1
part1 += j + 1
part2 = 0
for a in A:
lower = p - a
upper = mid + p - a
lower = max(lower, 0)
upper = min(upper, p - 1)
if lower > upper:
continue
left = bisect.bisect_left(B, lower)
right = bisect.bisect_right(B, upper)
part2 += (right - left)
total = part1 + part2
if total >= k:
ans = mid
high = mid - 1
else:
low = mid + 1
print(ans)
gew1fw