結果

問題 No.1597 Matrix Sort
ユーザー H3PO4H3PO4
提出日時 2023-03-30 09:26:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 366 ms / 1,500 ms
コード長 612 bytes
コンパイル時間 249 ms
コンパイル使用メモリ 81,784 KB
実行使用メモリ 173,248 KB
最終ジャッジ日時 2023-10-21 19:36:16
合計ジャッジ時間 9,604 ms
ジャッジサーバーID
(参考情報)
judge12 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,560 KB
testcase_01 AC 38 ms
53,560 KB
testcase_02 AC 38 ms
53,560 KB
testcase_03 AC 283 ms
170,004 KB
testcase_04 AC 309 ms
173,184 KB
testcase_05 AC 366 ms
173,188 KB
testcase_06 AC 363 ms
173,176 KB
testcase_07 AC 291 ms
170,000 KB
testcase_08 AC 282 ms
169,952 KB
testcase_09 AC 283 ms
169,948 KB
testcase_10 AC 171 ms
169,576 KB
testcase_11 AC 189 ms
172,508 KB
testcase_12 AC 131 ms
93,868 KB
testcase_13 AC 201 ms
102,816 KB
testcase_14 AC 339 ms
173,160 KB
testcase_15 AC 140 ms
94,812 KB
testcase_16 AC 170 ms
102,764 KB
testcase_17 AC 268 ms
173,128 KB
testcase_18 AC 331 ms
173,164 KB
testcase_19 AC 274 ms
173,176 KB
testcase_20 AC 237 ms
173,248 KB
testcase_21 AC 232 ms
173,168 KB
testcase_22 AC 222 ms
173,120 KB
testcase_23 AC 196 ms
170,216 KB
testcase_24 AC 100 ms
98,372 KB
testcase_25 AC 91 ms
99,376 KB
testcase_26 AC 38 ms
53,560 KB
testcase_27 AC 38 ms
53,560 KB
testcase_28 AC 38 ms
53,560 KB
testcase_29 AC 96 ms
137,596 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 = -1, P
while r - l > 1:
    m = (r + l) // 2
    if lower(m) >= K:
        r = m
    else:
        l = m
print(r)
0