結果

問題 No.1597 Matrix Sort
ユーザー gew1fw
提出日時 2025-06-12 16:39:24
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,215 bytes
コンパイル時間 244 ms
コンパイル使用メモリ 82,292 KB
実行使用メモリ 116,932 KB
最終ジャッジ日時 2025-06-12 16:39:53
合計ジャッジ時間 28,737 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18 TLE * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

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]))
    B.sort()
    
    low = 0
    high = P - 1
    ans = 0
    
    while low <= high:
        mid = (low + high) // 2
        count = 0
        
        for a in A:
            s = a
            if mid < s:
                low_b = P - s
                high_b = mid + (P - s)
                high_b = min(high_b, P - 1)
                l = bisect.bisect_left(B, low_b)
                r = bisect.bisect_right(B, high_b)
                cnt = r - l
            else:
                val1 = mid - s
                count1 = bisect.bisect_right(B, val1)
                val2 = P - s
                pos = bisect.bisect_left(B, val2)
                count2 = len(B) - pos
                cnt = count1 + count2
            count += cnt
        
        if count >= K:
            ans = mid
            high = mid - 1
        else:
            low = mid + 1
    
    print(ans)

find_kth_smallest()
0