結果

問題 No.1597 Matrix Sort
ユーザー NSNS
提出日時 2021-07-10 14:34:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 376 ms / 1,500 ms
コード長 847 bytes
コンパイル時間 311 ms
コンパイル使用メモリ 87,128 KB
実行使用メモリ 169,216 KB
最終ジャッジ日時 2023-09-14 19:25:52
合計ジャッジ時間 8,059 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,336 KB
testcase_01 AC 76 ms
71,076 KB
testcase_02 AC 76 ms
71,356 KB
testcase_03 AC 376 ms
168,656 KB
testcase_04 AC 353 ms
168,836 KB
testcase_05 AC 307 ms
168,620 KB
testcase_06 AC 301 ms
168,684 KB
testcase_07 AC 293 ms
168,040 KB
testcase_08 AC 263 ms
168,472 KB
testcase_09 AC 273 ms
168,676 KB
testcase_10 AC 199 ms
167,232 KB
testcase_11 AC 210 ms
168,220 KB
testcase_12 AC 178 ms
102,848 KB
testcase_13 AC 207 ms
100,864 KB
testcase_14 AC 326 ms
169,180 KB
testcase_15 AC 166 ms
103,004 KB
testcase_16 AC 187 ms
100,820 KB
testcase_17 AC 244 ms
169,216 KB
testcase_18 AC 311 ms
168,672 KB
testcase_19 AC 267 ms
168,596 KB
testcase_20 AC 236 ms
169,120 KB
testcase_21 AC 232 ms
168,784 KB
testcase_22 AC 223 ms
168,492 KB
testcase_23 AC 208 ms
167,364 KB
testcase_24 AC 124 ms
102,048 KB
testcase_25 AC 113 ms
101,436 KB
testcase_26 AC 77 ms
71,028 KB
testcase_27 AC 76 ms
71,028 KB
testcase_28 AC 75 ms
71,332 KB
testcase_29 AC 136 ms
153,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,k,p=map(int, input().split())
al=list(map(int, input().split()))
bl=list(map(int, input().split()))
al.sort()
bl.sort()

bcl=[0]*(p+1)
for b in bl:
    bcl[b]+=1
for i in range(p):
    bcl[i+1]+=bcl[i]

# print(bcl)

def check_cnt(val):
    res=0
    for a in al:
        # cnt1 = bisect_right(bl, val-a)
        # # cnt2 = n - bisect_left(bl, p-a)
        # cnt2 = n - bisect_right(bl, p-a-1)
        # cnt3 = n - bisect_right(bl, val+p-a)
        # print(val-a, p-a-1)
        if val-a<0:
            cnt1=0
        else:
            cnt1=bcl[max(val-a,0)]
        cnt2=bcl[min(p,val+p-a)]-bcl[p-a-1]
        res+=(cnt1+cnt2)
    return res

ok, ng = 0, p
ok, ng = p-1, -1
while abs(ok-ng) > 1:
    mid = (ok+ng)//2
    res = True
    # ...
    cnt=check_cnt(mid)
    # print('---',mid,cnt)
    if cnt>=k: ok = mid
    else: ng = mid
print(ok)
0