結果
| 問題 | No.1597 Matrix Sort |
| コンテスト | |
| ユーザー |
wolgnik
|
| 提出日時 | 2021-07-09 22:30:33 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 470 ms / 1,500 ms |
| コード長 | 530 bytes |
| コンパイル時間 | 178 ms |
| コンパイル使用メモリ | 82,028 KB |
| 実行使用メモリ | 258,432 KB |
| 最終ジャッジ日時 | 2024-07-01 17:09:40 |
| 合計ジャッジ時間 | 9,050 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
import sys
input = sys.stdin.readline
N, K, P = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
bc = [0] * P
for x in b: bc[x] += 1
cs = [0] * (P + 1)
for i in range(P): cs[i + 1] = cs[i] + bc[i]
def check(x):
c = 0
for y in a:
l = (P - y) % P
r = (P - y + x) % P
if l <= r: c += cs[r + 1] - cs[l]
else: c += cs[-1] - cs[l] + cs[r + 1]
return c >= K
ok = P - 1
ng = -1
while ok - ng > 1:
m = (ok + ng) // 2
if check(m): ok = m
else: ng = m
print(ok)
wolgnik