結果
問題 |
No.1597 Matrix Sort
|
ユーザー |
![]() |
提出日時 | 2025-03-31 17:24:28 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,407 bytes |
コンパイル時間 | 200 ms |
コンパイル使用メモリ | 82,340 KB |
実行使用メモリ | 116,700 KB |
最終ジャッジ日時 | 2025-03-31 17:24:59 |
合計ジャッジ時間 | 8,775 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 3 |
other | AC * 3 TLE * 5 -- * 19 |
ソースコード
import bisect def main(): 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])) B.sort() left = 0 right = p - 1 ans = p # Initialize with a value larger than possible maximum while left <= right: mid = (left + right) // 2 total = 0 for a in A: # First part: B_j <= mid - a if mid >= a if mid >= a: s1 = mid - a c1 = bisect.bisect_right(B, s1) else: c1 = 0 # Second part: B_j in [p - a, mid + (p - a)] mod p start = p - a end = mid + (p - a) end = min(end, p - 1) if start > end: c2 = 0 else: # Find the count of B elements in [start, end] l = bisect.bisect_left(B, start) r = bisect.bisect_right(B, end) c2 = r - l total += c1 + c2 if total >= k: ans = mid right = mid - 1 else: left = mid + 1 print(ans) if __name__ == "__main__": main()