結果
問題 |
No.1597 Matrix Sort
|
ユーザー |
![]() |
提出日時 | 2025-06-12 16:40:40 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,237 bytes |
コンパイル時間 | 158 ms |
コンパイル使用メモリ | 82,704 KB |
実行使用メモリ | 116,692 KB |
最終ジャッジ日時 | 2025-06-12 16:41:13 |
合計ジャッジ時間 | 29,846 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 TLE * 10 |
ソースコード
import bisect def find_kth_smallest(): import sys input = sys.stdin.read data = input().split() idx = 0 N = int(data[idx]) idx += 1 K = int(data[idx]) idx += 1 P = int(data[idx]) idx += 1 A = list(map(int, data[idx:idx+N])) idx += N B = list(map(int, data[idx:idx+N])) idx += N B.sort() low = 0 high = P - 1 ans = high while low <= high: mid = (low + high) // 2 total = 0 for s in A: if mid >= s: x = mid - s cnt1 = bisect.bisect_right(B, x) else: cnt1 = 0 lower = P - s upper = mid + P - s upper = min(upper, P - 1) if upper < lower: cnt2 = 0 else: left = bisect.bisect_left(B, lower) right = bisect.bisect_right(B, upper) cnt2 = right - left total += cnt1 + cnt2 if total > K: break if total >= K: ans = mid high = mid - 1 else: low = mid + 1 print(ans) find_kth_smallest()