結果
| 問題 |
No.3016 ハチマキおじさん
|
| コンテスト | |
| ユーザー |
eve__fuyuki
|
| 提出日時 | 2025-01-31 22:41:40 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 129 ms / 2,000 ms |
| コード長 | 849 bytes |
| コンパイル時間 | 2,410 ms |
| コンパイル使用メモリ | 203,912 KB |
| 実行使用メモリ | 14,208 KB |
| 最終ジャッジ日時 | 2025-01-31 22:41:48 |
| 合計ジャッジ時間 | 6,659 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 31 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
void fast_io() {
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
}
int main() {
fast_io();
int n;
cin >> n;
vector<long long> a(n), b(n - 1);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n - 1; i++) {
cin >> b[i];
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
vector<long long> cum(n), cum2(n);
for (int i = 0; i < n - 1; i++) {
cum[i + 1] = cum[i] + abs(a[i] - b[i]);
cum2[i + 1] = cum2[i] + abs(a[i + 1] - b[i]);
}
set<long long> ans;
long long mi = 9e18;
for (int i = 0; i < n; i++) {
long long x = cum[i] + cum2[n - 1] - cum2[i];
if (x < mi) {
mi = x;
ans.clear();
ans.insert(a[i]);
} else if (x == mi) {
ans.insert(a[i]);
}
}
cout << ans.size() << "\n";
for (auto x : ans) {
cout << x << ' ';
}
cout << "\n";
}
eve__fuyuki