結果

問題 No.1597 Matrix Sort
ユーザー roarisroaris
提出日時 2021-07-12 10:44:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 942 ms / 1,500 ms
コード長 652 bytes
コンパイル時間 460 ms
コンパイル使用メモリ 87,232 KB
実行使用メモリ 378,012 KB
最終ジャッジ日時 2023-09-14 20:30:54
合計ジャッジ時間 16,437 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,272 KB
testcase_01 AC 69 ms
71,156 KB
testcase_02 AC 70 ms
71,120 KB
testcase_03 AC 942 ms
376,572 KB
testcase_04 AC 833 ms
376,792 KB
testcase_05 AC 707 ms
378,012 KB
testcase_06 AC 706 ms
376,556 KB
testcase_07 AC 706 ms
376,620 KB
testcase_08 AC 676 ms
377,656 KB
testcase_09 AC 646 ms
377,308 KB
testcase_10 AC 605 ms
375,632 KB
testcase_11 AC 602 ms
377,564 KB
testcase_12 AC 121 ms
102,064 KB
testcase_13 AC 193 ms
172,140 KB
testcase_14 AC 712 ms
377,484 KB
testcase_15 AC 131 ms
102,656 KB
testcase_16 AC 196 ms
171,824 KB
testcase_17 AC 665 ms
377,932 KB
testcase_18 AC 722 ms
377,096 KB
testcase_19 AC 694 ms
377,100 KB
testcase_20 AC 633 ms
376,656 KB
testcase_21 AC 641 ms
376,836 KB
testcase_22 AC 660 ms
377,608 KB
testcase_23 AC 623 ms
375,692 KB
testcase_24 AC 111 ms
101,356 KB
testcase_25 AC 104 ms
101,116 KB
testcase_26 AC 69 ms
71,320 KB
testcase_27 AC 71 ms
71,208 KB
testcase_28 AC 70 ms
71,040 KB
testcase_29 AC 592 ms
363,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

def judge(x):
    cnt = 0
    
    for Ai in A:
        if x>=Ai:
            cnt += acc[x-Ai+1]+acc[P]-acc[P-Ai]
        else:
            cnt += acc[P-Ai+x+1]-acc[P-Ai]
    
    return cnt>=K
            
def binary_search():
    l, r = 0, P-1
    
    while l<=r:
        m = (l+r)//2
        
        if judge(m):
            r = m-1
        else:
            l = m+1
    
    return l

N, K, P = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = [0]*P

for Bi in B:
    C[Bi] += 1

acc = [0]

for Ci in C:
    acc.append(acc[-1]+Ci)

print(binary_search())
0