結果
問題 |
No.3016 ハチマキおじさん
|
ユーザー |
|
提出日時 | 2025-09-05 23:12:19 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 123 ms / 2,000 ms |
コード長 | 852 bytes |
コンパイル時間 | 2,091 ms |
コンパイル使用メモリ | 205,320 KB |
実行使用メモリ | 14,336 KB |
最終ジャッジ日時 | 2025-09-05 23:12:26 |
合計ジャッジ時間 | 7,239 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 31 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll N, minAns = LLONG_MAX; cin >> N; vector<ll> A(N), B(N - 1), L(N), R(N); set<ll> ans; 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()); for(int i=0; i<N-1; i++) L[i+1] = L[i] + abs(A[i] - B[i]); for(int i=N-1; i>0; i--) R[i-1] = R[i] + abs(A[i] - B[i-1]); for(int i=0; i<N; i++) { if(minAns >= L[i] + R[i]) { if(minAns > L[i] + R[i]) if(!ans.empty()) ans.clear(); ans.insert(A[i]); minAns = L[i] + R[i]; } } cout << ans.size() << endl; for(auto it=ans.begin(); it!=ans.end(); it++) cout << *it << " \n"[next(it) == ans.end()]; }