結果
| 問題 | No.1597 Matrix Sort |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-07-09 22:01:22 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 426 ms / 1,500 ms |
| コード長 | 558 bytes |
| コンパイル時間 | 175 ms |
| コンパイル使用メモリ | 82,848 KB |
| 実行使用メモリ | 182,204 KB |
| 最終ジャッジ日時 | 2024-07-01 16:23:23 |
| 合計ジャッジ時間 | 7,155 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
from itertools import count
n,k,p = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
sA = [a%p for a in A]
cum = [0]*p
for b in B:
cum[b%p] += 1
for i in range(p-1):
cum[i+1] += cum[i]
def count(x):
ans = 0
for a in sA:
ans += cum[(-a%p+x)%p]
if (-a)%p != 0:
ans -= cum[-a%p-1]
if (-a%p+x)%p < -a%p:
ans += cum[-1]
return ans
l = -1
r = p-1
while r > l+1:
m = (r+l)//2
if count(m) < k:
l = m
else:
r = m
print(r)