結果

問題 No.3016 ハチマキおじさん
ユーザー cho435
提出日時 2025-02-22 02:20:34
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 119 ms / 2,000 ms
コード長 1,073 bytes
コンパイル時間 4,619 ms
コンパイル使用メモリ 263,320 KB
実行使用メモリ 24,576 KB
最終ジャッジ日時 2025-02-22 02:21:23
合計ジャッジ時間 7,389 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, t) for (ll i = s; i < (ll)(t); i++)

template<typename T>
bool chmin(T &x, T y) { return x > y ? (x = y, true) : false; }
template<typename T>
bool chmax(T &x, T y) { return x < y ? (x = y, true) : false; }

struct io_setup {
	io_setup() {
		ios::sync_with_stdio(false);
		std::cin.tie(nullptr);
		cout << fixed << setprecision(15);
	}
} io_setup;

int main(){
	int n;
	cin>>n;
	vector<int> a(n),b(n-1);
	rep(i,0,n) cin>>a[i];
	rep(i,0,n-1) cin>>b[i];
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	vector<ll> dp(n,0);
	rep(i,0,n-1){
		dp[i+1]=dp[i]+abs(a[i]-b[i]);
	}
	vector<ll> rdp(n,0);
	reverse(a.begin(),a.end());
	reverse(b.begin(),b.end());
	rep(i,0,n-1){
		rdp[i+1]=rdp[i]+abs(a[i]-b[i]);
	}
	reverse(rdp.begin(),rdp.end());
	reverse(a.begin(),a.end());
	reverse(b.begin(),b.end());
	map<int,set<int>> mp;
	rep(i,0,n){
		mp[dp[i]+rdp[i]].insert(a[i]);
	}
	auto[mn,st]=*mp.begin();
	cout<<st.size()<<"\n";
	for(int x:st) cout<<x<<" ";
	cout<<"\n";
}
0