結果

問題 No.1597 Matrix Sort
ユーザー marroncastlemarroncastle
提出日時 2021-07-10 00:57:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 372 ms / 1,500 ms
コード長 673 bytes
コンパイル時間 1,896 ms
コンパイル使用メモリ 86,668 KB
実行使用メモリ 170,564 KB
最終ジャッジ日時 2023-09-14 12:21:39
合計ジャッジ時間 9,044 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,092 KB
testcase_01 AC 75 ms
71,216 KB
testcase_02 AC 76 ms
71,096 KB
testcase_03 AC 372 ms
170,176 KB
testcase_04 AC 368 ms
170,248 KB
testcase_05 AC 308 ms
170,168 KB
testcase_06 AC 299 ms
170,056 KB
testcase_07 AC 272 ms
169,060 KB
testcase_08 AC 257 ms
169,200 KB
testcase_09 AC 262 ms
169,068 KB
testcase_10 AC 193 ms
167,456 KB
testcase_11 AC 208 ms
169,204 KB
testcase_12 AC 176 ms
100,116 KB
testcase_13 AC 193 ms
99,992 KB
testcase_14 AC 320 ms
170,152 KB
testcase_15 AC 164 ms
100,716 KB
testcase_16 AC 178 ms
99,708 KB
testcase_17 AC 237 ms
170,084 KB
testcase_18 AC 303 ms
170,228 KB
testcase_19 AC 260 ms
170,144 KB
testcase_20 AC 238 ms
170,308 KB
testcase_21 AC 229 ms
170,564 KB
testcase_22 AC 225 ms
169,552 KB
testcase_23 AC 206 ms
168,576 KB
testcase_24 AC 119 ms
103,140 KB
testcase_25 AC 109 ms
102,844 KB
testcase_26 AC 73 ms
71,380 KB
testcase_27 AC 72 ms
71,240 KB
testcase_28 AC 72 ms
71,316 KB
testcase_29 AC 126 ms
153,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys,os,io
input = sys.stdin.readline
#input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
N, K, P = map(int, input().split())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
lis = [0]*P
for i in range(N): lis[B[i]] += 1
for i in range(1,P): lis[i] += lis[i-1]

from bisect import *
def check(target):
    cnt = 0
    for i in range(N):
        t = target - A[i]
        if t >= 0: cnt += lis[t]
        cnt += lis[min(P-1, t+P)] - lis[P-1-A[i]]
    return cnt >= K

low,high = -1,P-1
mid = (low+high)//2
while high-low>1:
    if check(mid): high = mid
    else: low = mid
    mid = (low+high)//2
ans = high
print(ans)
0