結果

問題 No.1597 Matrix Sort
ユーザー convexineqconvexineq
提出日時 2021-07-09 21:52:13
言語 PyPy3
(7.3.8)
結果
AC  
実行時間 362 ms / 1,500 ms
コード長 667 bytes
コンパイル時間 894 ms
使用メモリ 104,916 KB
最終ジャッジ日時 2023-02-01 23:07:24
合計ジャッジ時間 9,594 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 82 ms
75,740 KB
testcase_01 AC 83 ms
75,788 KB
testcase_02 AC 83 ms
75,816 KB
testcase_03 AC 345 ms
102,644 KB
testcase_04 AC 362 ms
102,456 KB
testcase_05 AC 360 ms
102,708 KB
testcase_06 AC 350 ms
102,740 KB
testcase_07 AC 333 ms
102,340 KB
testcase_08 AC 305 ms
102,572 KB
testcase_09 AC 303 ms
102,264 KB
testcase_10 AC 161 ms
99,964 KB
testcase_11 AC 231 ms
100,972 KB
testcase_12 AC 250 ms
101,688 KB
testcase_13 AC 315 ms
101,760 KB
testcase_14 AC 336 ms
102,688 KB
testcase_15 AC 220 ms
102,144 KB
testcase_16 AC 265 ms
101,588 KB
testcase_17 AC 281 ms
102,520 KB
testcase_18 AC 344 ms
102,664 KB
testcase_19 AC 294 ms
102,392 KB
testcase_20 AC 267 ms
102,776 KB
testcase_21 AC 251 ms
102,644 KB
testcase_22 AC 243 ms
102,220 KB
testcase_23 AC 183 ms
100,732 KB
testcase_24 AC 142 ms
104,820 KB
testcase_25 AC 130 ms
104,916 KB
testcase_26 AC 83 ms
75,560 KB
testcase_27 AC 81 ms
75,440 KB
testcase_28 AC 82 ms
75,784 KB
testcase_29 AC 81 ms
75,668 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline

n,k,p = map(int,readline().split())
*a, = map(int,readline().split())
*b, = map(int,readline().split())
a.sort()
b.sort()

def check(x): # x 以下の数は k 個以上か?
    res = 0
    R = L1 = R1 = n-1
    for ai in a:
        while R >= 0 and ai+b[R] > x:
            R -= 1
        res += R+1
        
        while L1 >= 0 and ai+b[L1] >= p:
            L1 -= 1
        while R1 >= 0 and ai+b[R1] > p+x:
            R1 -= 1
        res += R1-L1
        #print(R,L1,R1)
    return res >= k

ng = -1
ok = p
while ok-ng > 1:
    mid = (ok+ng)//2
    if check(mid):
        ok = mid
    else:
        ng = mid
print(ok)
0