結果
| 問題 |
No.1597 Matrix Sort
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-16 16:30:42 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,359 bytes |
| コンパイル時間 | 293 ms |
| コンパイル使用メモリ | 82,280 KB |
| 実行使用メモリ | 123,768 KB |
| 最終ジャッジ日時 | 2025-04-16 16:32:22 |
| 合計ジャッジ時間 | 9,990 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 3 |
| other | AC * 3 TLE * 4 -- * 20 |
ソースコード
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]))
idx += n
A.sort()
low = 0
high = p - 1
ans = 0
while low <= high:
mid = (low + high) // 2
total = 0
for b in B:
# Interval 1: [0, mid - b] if mid >= b
cnt1 = 0
if mid >= b:
r1 = mid - b
if r1 >= 0:
cnt1 = bisect.bisect_right(A, r1) - bisect.bisect_left(A, 0)
# Interval 2: [P - b, mid + P - b] clamped to [0, P-1]
l2 = p - b
r2 = mid + p - b
actual_l = max(l2, 0)
actual_r = min(r2, p - 1)
cnt2 = 0
if actual_l <= actual_r:
left = bisect.bisect_left(A, actual_l)
right = bisect.bisect_right(A, actual_r)
cnt2 = right - left
total += cnt1 + cnt2
if total >= k:
ans = mid
high = mid - 1
else:
low = mid + 1
print(ans)
if __name__ == "__main__":
main()
lam6er