結果
問題 | No.1467 Selling Cars |
ユーザー |
![]() |
提出日時 | 2021-03-12 13:25:23 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,242 bytes |
コンパイル時間 | 1,905 ms |
コンパイル使用メモリ | 182,284 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-13 23:17:13 |
合計ジャッジ時間 | 12,304 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 4 WA * 27 |
ソースコード
#include <bits/stdc++.h>int ri() {int n;scanf("%d", &n);return n;}int64_t fast_one(const std::vector<int64_t> &a, const std::vector<int64_t> &b, int k) {std::map<int, int> left;for (auto i : a) left[i] += k;int64_t res = 0;for (auto i : b) {auto itr = left.lower_bound(i);if (itr == left.end()) itr--;else if (itr != left.begin() && std::abs(i - itr->first) >= std::abs(i - std::prev(itr)->first)) itr--;res += std::abs(i - itr->first);if (!--itr->second) left.erase(itr);}return res;}std::vector<int64_t> fast(std::vector<int> a_, std::vector<int> b_) {std::sort(a_.begin(), a_.end());std::sort(b_.begin(), b_.end());std::vector<int64_t> a(a_.begin(), a_.end());std::vector<int64_t> b(b_.begin(), b_.end());int n = a.size();int m = b.size();a.insert(a.begin(), -1000000000000000000);a.insert(a.end(), 1000000000000000000);(void) n;std::vector<int64_t> res;for (int i = 1; i <= m; i++) res.push_back(fast_one(a, b, i));return res;}int main() {int m = ri();int n = ri();std::vector<int> a(m);std::vector<int> b(n);for (auto &i : a) i = ri();for (auto &i : b) i = ri();auto res = fast(b, a);for (auto i : res) printf("%" PRId64 "\n", i);return 0;}