結果

問題 No.1597 Matrix Sort
ユーザー H3PO4H3PO4
提出日時 2023-03-29 14:58:17
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 615 bytes
コンパイル時間 149 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 173,080 KB
最終ジャッジ日時 2023-10-21 06:27:14
合計ジャッジ時間 7,354 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,444 KB
testcase_01 AC 34 ms
53,444 KB
testcase_02 AC 35 ms
53,444 KB
testcase_03 WA -
testcase_04 AC 274 ms
173,012 KB
testcase_05 AC 306 ms
173,012 KB
testcase_06 AC 312 ms
173,008 KB
testcase_07 AC 250 ms
169,824 KB
testcase_08 AC 223 ms
169,784 KB
testcase_09 AC 229 ms
169,780 KB
testcase_10 AC 159 ms
169,408 KB
testcase_11 AC 175 ms
172,340 KB
testcase_12 AC 118 ms
93,732 KB
testcase_13 AC 168 ms
102,648 KB
testcase_14 AC 297 ms
172,992 KB
testcase_15 AC 130 ms
94,676 KB
testcase_16 AC 152 ms
102,588 KB
testcase_17 AC 239 ms
172,972 KB
testcase_18 AC 288 ms
173,004 KB
testcase_19 AC 248 ms
173,000 KB
testcase_20 AC 215 ms
173,080 KB
testcase_21 AC 216 ms
172,996 KB
testcase_22 AC 202 ms
172,952 KB
testcase_23 AC 194 ms
172,948 KB
testcase_24 AC 86 ms
99,240 KB
testcase_25 AC 85 ms
99,240 KB
testcase_26 WA -
testcase_27 AC 33 ms
53,444 KB
testcase_28 AC 32 ms
53,444 KB
testcase_29 AC 88 ms
137,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, K, P = map(int, input().split())
A = tuple(int(x) % P for x in input().split())
B = sorted(int(x) % P for x in input().split())

B_counter = [0] * P
for b in B:
    B_counter[b] += 1
for i in range(1, P):
    B_counter[i] += B_counter[i - 1]


def lower(x):
    ct = 0
    for a in A:
        b1 = B_counter[x - a] if x - a >= 0 else 0
        b2 = B_counter[P + x - a] if P + x - a < P else N
        assert 0 <= P - a - 1 < P
        ct += b1 + b2 - B_counter[P - a - 1]
    return ct


l, r = 0, P
while r - l > 1:
    m = (r + l) // 2
    if lower(m) >= K:
        r = m
    else:
        l = m
print(l + 1)
0