結果

問題 No.1597 Matrix Sort
ユーザー convexineqconvexineq
提出日時 2021-07-09 21:52:13
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 344 ms / 1,500 ms
コード長 667 bytes
コンパイル時間 270 ms
コンパイル使用メモリ 87,292 KB
実行使用メモリ 102,236 KB
最終ジャッジ日時 2023-09-14 08:44:06
合計ジャッジ時間 8,316 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,292 KB
testcase_01 AC 72 ms
71,420 KB
testcase_02 AC 69 ms
71,472 KB
testcase_03 AC 328 ms
96,408 KB
testcase_04 AC 344 ms
96,632 KB
testcase_05 AC 340 ms
96,568 KB
testcase_06 AC 336 ms
96,572 KB
testcase_07 AC 318 ms
96,320 KB
testcase_08 AC 287 ms
96,596 KB
testcase_09 AC 286 ms
96,868 KB
testcase_10 AC 145 ms
98,440 KB
testcase_11 AC 210 ms
95,636 KB
testcase_12 AC 235 ms
100,352 KB
testcase_13 AC 300 ms
97,604 KB
testcase_14 AC 324 ms
96,636 KB
testcase_15 AC 204 ms
101,144 KB
testcase_16 AC 247 ms
97,624 KB
testcase_17 AC 264 ms
96,464 KB
testcase_18 AC 325 ms
96,612 KB
testcase_19 AC 280 ms
96,464 KB
testcase_20 AC 250 ms
96,464 KB
testcase_21 AC 236 ms
96,564 KB
testcase_22 AC 228 ms
96,188 KB
testcase_23 AC 164 ms
97,976 KB
testcase_24 AC 128 ms
102,236 KB
testcase_25 AC 111 ms
102,096 KB
testcase_26 AC 67 ms
71,400 KB
testcase_27 AC 67 ms
71,140 KB
testcase_28 AC 68 ms
71,480 KB
testcase_29 AC 67 ms
71,148 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