题目:http://codeforces.com/contest/1419/problem/D2
本来写的是easy version的代码,交hard version竟然能过
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,a,b) for(ll i=a;i<=b;i++) #define endl ' ' #define V vector #define pb(x) push_back(x); const ll amn=1e5+5; ll a[amn]; int main(){ ios::sync_with_stdio(0); ll T=1; // cin>>T; while(T--){ ll n;cin>>n; rep(i,1,n){ cin>>a[i]; } sort(a+1,a+1+n); V<ll> aa,bb,ans; aa.clear(); bb.clear(); ans.clear(); rep(i,1,n/2)aa.pb(a[i]); rep(i,n/2+1,n)bb.pb(a[i]); // cout<<n/2<<' '<<aa.size()<<' '<<bb.size()<<endl; for(ll i=0,j=0;i<aa.size()||j<bb.size();i++,j++){ if(j<bb.size())ans.pb(bb[i]); if(i<aa.size())ans.pb(aa[i]); } ll cnt=0; rep(i,0,ans.size()-1){ if(i-1>=0&&i+1<ans.size()&&ans[i-1]>ans[i]&&ans[i]<ans[i+1])cnt++; } cout<<cnt<<endl; rep(i,0,ans.size()-1)cout<<ans[i]<<' ';cout<<endl; } }