//#define NDEBUG #include #include #include #include #include #include #include namespace n91 { using i32 = std::int32_t; using i64 = std::int64_t; using u32 = std::uint32_t; using u64 = std::uint64_t; using isize = std::ptrdiff_t; using usize = std::size_t; struct rep { struct itr { usize i; constexpr itr(const usize i) noexcept : i(i) {} void operator++() noexcept { ++i; } constexpr usize operator*() const noexcept { return i; } constexpr bool operator!=(const itr x) const noexcept { return i != x.i; } }; const itr f, l; constexpr rep(const usize f, const usize l) noexcept : f(std::min(f, l)), l(l) {} constexpr auto begin() const noexcept { return f; } constexpr auto end() const noexcept { return l; } }; struct revrep { struct itr { usize i; constexpr itr(const usize i) noexcept : i(i) {} void operator++() noexcept { --i; } constexpr usize operator*() const noexcept { return i; } constexpr bool operator!=(const itr x) const noexcept { return i != x.i; } }; const itr f, l; constexpr revrep(const usize f, const usize l) noexcept : f(l - 1), l(std::min(f, l) - 1) {} constexpr auto begin() const noexcept { return f; } constexpr auto end() const noexcept { return l; } }; template auto md_vec(const usize n, const T &value) { return std::vector(n, value); } template auto md_vec(const usize n, Args... args) { return std::vector(n, md_vec(args...)); } template constexpr T difference(const T &a, const T &b) noexcept { return a < b ? b - a : a - b; } template void chmin(T &a, const T &b) noexcept { if (b < a) a = b; } template void chmax(T &a, const T &b) noexcept { if (a < b) a = b; } template class rec_lambda { F f; public: rec_lambda(F &&f) : f(std::move(f)) {} template auto operator()(Args &&... args) const { return f(*this, std::forward(args)...); } }; template auto make_rec(F &&f) { return rec_lambda(std::move(f)); } template T scan() { T ret; std::cin >> ret; return ret; } constexpr char eoln = '\n'; template T ceildiv(const T &l, const T &r) { return l / r + (l % r != 0 ? 1 : 0); } } // namespace n91 #include namespace n91 { void main_() { /* std::ios::sync_with_stdio(false); std::cin.tie(nullptr); //*/ const usize m = scan(); const usize n = scan(); /* std::vector a(m),b(b); for(auto &e:a){ std::cin>>e; } for(auto &e:b){ std::cin>>e; } */ struct vtx { int type; // 0:a, 1:b i64 v; }; std::vector vs; for (const usize i : rep(0, m)) { const i64 a = scan(); vs.push_back({0, a}); } for (const usize i : rep(0, n)) { const i64 b = scan(); vs.push_back({1, b}); } std::sort(vs.begin(), vs.end(), [](const auto &l, const auto &r) { return l.v < r.v; }); struct aque { std::deque> v; i64 a; aque() : v(), a(0) {} void push_front(i64 x, i64 l) { v.push_front({x - a, l}); } void push_back(i64 x, i64 l) { v.push_back({x - a, l}); } bool empty() { return v.empty(); } i64 front() { return v.front().first + a; } std::pair pop_front() { auto ret = v.front(); v.pop_front(); return {ret.first + a, ret.second}; } std::pair pop_back() { auto ret = v.back(); v.pop_back(); return {ret.first + a, ret.second}; } void add(i64 x) { a += x; } }; for (const usize k : rep(1, m + 1)) { i64 min_pos = 0; i64 min_val = 0; aque m, r; r.push_back(1e13, 1e4); const auto shift = [&]() { auto [s, len] = m.pop_front(); min_pos += len; min_val += s * len; }; i64 prev = 0; for (const auto &[type, x] : vs) { const i64 dif = (x - prev); min_val += dif * (-min_pos); m.add(-dif); r.add(dif); while (!m.empty() && m.front() < 0) { shift(); } if (type == 0) { min_pos -= 1; assert(!r.empty()); auto [s, len] = r.pop_front(); m.push_back(s, 1); if (len - 1 != 0) { r.push_front(s, len - 1); } } else { m.push_front(0, k); i64 m_r = k; while (m_r != 0) { assert(!m.empty()); auto [s, len] = m.pop_back(); const i64 t = std::min(len, m_r); r.push_front(s, t); m_r -= t; if (len - t != 0) { m.push_back(s, len - t); } } } prev = x; } while (!m.empty()) { shift(); } std::cout << min_val << eoln; } } } // namespace n91 int main() { n91::main_(); return 0; }