結果
問題 |
No.1597 Matrix Sort
|
ユーザー |
![]() |
提出日時 | 2025-06-12 13:32:53 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 827 bytes |
コンパイル時間 | 250 ms |
コンパイル使用メモリ | 82,712 KB |
実行使用メモリ | 105,044 KB |
最終ジャッジ日時 | 2025-06-12 13:39:39 |
合計ジャッジ時間 | 5,103 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 TLE * 1 |
ソースコード
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)