結果

問題 No.1597 Matrix Sort
ユーザー taiga0629kyoprotaiga0629kyopro
提出日時 2021-07-09 22:12:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,379 ms / 1,500 ms
コード長 1,239 bytes
コンパイル時間 296 ms
コンパイル使用メモリ 87,104 KB
実行使用メモリ 103,172 KB
最終ジャッジ日時 2023-09-14 09:22:42
合計ジャッジ時間 24,275 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
71,332 KB
testcase_01 AC 69 ms
71,388 KB
testcase_02 AC 73 ms
71,468 KB
testcase_03 AC 210 ms
99,656 KB
testcase_04 AC 1,347 ms
100,048 KB
testcase_05 AC 1,332 ms
99,688 KB
testcase_06 AC 1,339 ms
99,592 KB
testcase_07 AC 1,345 ms
99,768 KB
testcase_08 AC 849 ms
99,420 KB
testcase_09 AC 896 ms
99,624 KB
testcase_10 AC 175 ms
100,712 KB
testcase_11 AC 172 ms
99,700 KB
testcase_12 AC 934 ms
100,104 KB
testcase_13 AC 1,208 ms
101,200 KB
testcase_14 AC 1,379 ms
99,988 KB
testcase_15 AC 794 ms
103,172 KB
testcase_16 AC 1,101 ms
101,240 KB
testcase_17 AC 1,195 ms
99,484 KB
testcase_18 AC 1,301 ms
99,768 KB
testcase_19 AC 1,237 ms
99,580 KB
testcase_20 AC 1,248 ms
99,720 KB
testcase_21 AC 1,254 ms
99,600 KB
testcase_22 AC 1,202 ms
100,280 KB
testcase_23 AC 901 ms
101,092 KB
testcase_24 AC 154 ms
102,264 KB
testcase_25 AC 111 ms
101,808 KB
testcase_26 AC 65 ms
71,620 KB
testcase_27 AC 67 ms
71,380 KB
testcase_28 AC 67 ms
71,284 KB
testcase_29 AC 74 ms
75,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,k,p=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a.sort()
b.sort()

####二分探索###################################

#配列は昇順にソートずみ
def bilower(a,x):
    # a[i]<=x となる最大のiを返す ない時は-1
    if len(a)==0:return -1
    mi=0
    ma=len(a)-1
    if a[0]>x:return -1
    if a[ma]<=x:return ma
    while ma-mi>1:
        mid=(ma+mi)//2
        if a[mid]<=x:mi=mid
        else:ma=mid
    return mi

def bihigher(a,x):
    # a[i]>=x となる最小のiを返す ない時は len(a)
    if len(a)==0:return 0
    mi=0
    ma=len(a)-1
    if a[ma]<x:return ma+1
    if a[0]>=x:return 0
    while ma-mi>1:
        mid=(ma+mi)//2
        if a[mid]>=x:ma=mid
        else:mi=mid
    return ma

def birange(a,l,r):
    #l<=a[i]<=r となるiの個数を返す
    left=bihigher(a,l)
    right=bilower(a,r)
    return right-left+1

################################################





def f(x):
    res=0
    for i in range(n):
        res+=birange(b,-a[i],x-a[i])
        res+=birange(b,p-a[i],x+p-a[i])
    return res

if f(0)>=k:
    print(0)
    exit()

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

print(ok)



0