結果

問題 No.1467 Selling Cars
ユーザー QCFiumQCFium
提出日時 2021-03-12 13:25:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,242 bytes
コンパイル時間 2,188 ms
コンパイル使用メモリ 178,568 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 00:44:19
合計ジャッジ時間 11,874 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 322 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0