結果
問題 | No.3016 ハチマキおじさん |
ユーザー |
|
提出日時 | 2025-01-25 13:57:03 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 179 ms / 2,000 ms |
コード長 | 1,201 bytes |
コンパイル時間 | 3,440 ms |
コンパイル使用メモリ | 280,440 KB |
実行使用メモリ | 7,936 KB |
最終ジャッジ日時 | 2025-01-25 23:03:29 |
合計ジャッジ時間 | 8,489 ms |
ジャッジサーバーID (参考情報) |
judge10 / judge7 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 31 |
ソースコード
#include <bits/stdc++.h> typedef long long ll; typedef std::pair<long long, long long> P; typedef std::priority_queue<P, std::vector<P>, std::greater<P>> PQ; int main() { int n; std::cin >> n; std::vector<ll> a(n), b(n - 1); for (int i = 0; i < n; ++i) { std::cin >> a[i]; } for (int i = 0; i < n - 1; ++i) { std::cin >> b[i]; } std::sort(a.begin(), a.end()); std::sort(b.begin(), b.end()); long long mi = 0; std::vector<long long> ans(n, 0); for (int i = 0; i < n - 1; ++i) { mi += abs(a[i] - b[i]); } ans[n - 1] = mi; ll cur = mi; for (int i = n - 2; i >= 0; --i) { cur -= abs(a[i] - b[i]); cur += abs(a[i + 1] - b[i]); mi = std::min(mi, cur); ans[i] = cur; } int count = 0; for (int i = 0; i < n; ++i) { if (ans[i] == mi && (i == 0 || a[i - 1] != a[i])) count++; } std::cout << count << std::endl; for (int i = 0; i < n; ++i) { if (ans[i] == mi && (i == 0 || a[i - 1] != a[i])) { std::cout << a[i]; count--; if (count == 0) std::cout << std::endl; else std::cout << ' '; } } }