結果
問題 | No.3016 ハチマキおじさん |
ユーザー |
|
提出日時 | 2025-01-25 12:34:50 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 84 ms / 2,000 ms |
コード長 | 711 bytes |
コンパイル時間 | 814 ms |
コンパイル使用メモリ | 71,976 KB |
実行使用メモリ | 8,576 KB |
最終ジャッジ日時 | 2025-01-25 22:04:38 |
合計ジャッジ時間 | 3,812 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 31 |
ソースコード
#include<iostream> #include<vector> #include<algorithm> #include<cassert> using namespace std; int N,A[2<<17],B[2<<17]; long L[2<<17],R[2<<17]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin>>N; for(int i=0;i<N;i++)cin>>A[i]; for(int i=0;i<N-1;i++)cin>>B[i]; sort(A,A+N); sort(B,B+N-1); L[0]=0; for(int i=0;i<N-1;i++)L[i+1]=L[i]+abs(A[i]-B[i]); R[N-1]=0; for(int i=N-1;i--;)R[i]=R[i+1]+abs(A[i+1]-B[i]); long mn=9e18; vector<int>ans; for(int i=0;i<N;i++) { long now=L[i]+R[i]; if(mn>now)mn=now,ans.clear(); if(mn==now&&(ans.empty()||ans.back()<A[i]))ans.push_back(A[i]); } cout<<ans.size()<<"\n"; for(int i=0;i<ans.size();i++)cout<<ans[i]<<(i+1==ans.size()?"\n":" "); }