結果
問題 |
No.3016 ハチマキおじさん
|
ユーザー |
![]() |
提出日時 | 2025-01-27 06:37:57 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 121 ms / 2,000 ms |
コード長 | 882 bytes |
コンパイル時間 | 3,918 ms |
コンパイル使用メモリ | 284,624 KB |
実行使用メモリ | 10,076 KB |
最終ジャッジ日時 | 2025-01-27 06:38:06 |
合計ジャッジ時間 | 8,903 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 31 |
ソースコード
#define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; #include<bits/stdc++.h> using namespace std; template<class T>using V=vector<T>; template<class T>using VV=V<V<T>>; int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int n; cin>>n; V<int> A(n),B(n-1); rep(i,n) cin>>A[i]; rep(i,n-1) cin>>B[i]; sort(ALL(A)); sort(ALL(B)); ll ans=0; V<int> ANS; set<int> s; for(int i=1;i<n;i++) ans+=abs(A[i]-B[i-1]); ll tmp=ans; s.insert(A[0]); for(int i=1;i<n;i++){ tmp-=abs(A[i]-B[i-1]); tmp+=abs(A[i-1]-B[i-1]); if(tmp==ans) s.insert(A[i]); else if(tmp<ans){ s.clear(); s.insert(A[i]); ans=tmp; } } for(auto x:s) ANS.push_back(x); int a=ANS.size(); cout<<a<<endl; rep(i,a){ if(i) cout<<" "; cout<<ANS[i]; } cout<<endl; return 0; }