結果
問題 | No.1467 Selling Cars |
ユーザー |
![]() |
提出日時 | 2021-03-12 11:57:55 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,134 bytes |
コンパイル時間 | 189 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 18,432 KB |
最終ジャッジ日時 | 2024-10-13 20:50:21 |
合計ジャッジ時間 | 10,641 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 2 |
other | TLE * 1 -- * 30 |
ソースコード
import collectionsdef fast_one(a, b, k) :n = len(a)m = len(b)used = [collections.deque() for i in range(n + 1)]closest = 0for i in range(m) :while closest + 1 < n and abs(b[i] - a[closest]) >= abs(b[i] - a[closest + 1]) : closest += 1if len(used[closest]) == k :r = closestl = closestwhile l and len(used[l - 1]) == k : l -= 1while r + 1 < n and len(used[r + 1]) == k : r += 1r += 1used[r].append(i)shift_delta = 0for j in range(l, r + 1) : shift_delta += abs(a[j - 1] - b[used[j][0]]) - abs(a[j] - b[used[j][0]])if shift_delta < 0 :for j in range(l, r + 1) :used[j - 1].append(used[j][0])used[j].popleft()else : used[closest].append(i)res = 0for i in range(n) :for j in used[i] : res += abs(a[i] - b[j])return resdef fast(a, b) :a.sort()b.sort()a = [-1000000000000000000] + a + [1000000000000000000]res = []for i in range(1, m + 1) : res.append(fast_one(a, b, i))return resm, n = map(int, input().split())a = list(map(int, input().split()))b = list(map(int, input().split()))res = fast(b, a)for i in res : print(i)