#include using namespace std; #define ALL(x) begin(x),end(x) #define rep(i,n) for(int i=0;i<(n);i++) #define debug(v) cout<<#v<<":";for(auto x:v){cout<bool chmax(T &a,const T &b){if(abool chmin(T &a,const T &b){if(b ostream &operator<<(ostream &os,const vector&v){ for(int i=0;i<(int)v.size();i++) os< istream &operator>>(istream &is,vector&v){ for(T &x:v)is>>x; return is; } /* え,もしかしてbeetさんのこれ,最強? 試させてください.なんでもします */ template struct Slope{ using P = pair; priority_queue, less

> L; priority_queue, greater

> R; T offset,entire; Slope():offset(0),entire(0){} inline T relu(T x){return max(0,x);} template inline void push(PQ &pq,T pos,T num){ if(num!=T(0)) pq.emplace(pos,num); } void add_x_minus_a(T a,T cnt=T(1)){ a-=offset; T use(0); while(use vp; vp.reserve(pq.size()); while(!pq.empty()) vp.emplace_back(pq.top()),pq.pop(); return vp; }; for(auto[pos,num]:vectorize(L)) res+=relu(pos-x)*num; for(auto[pos,num]:vectorize(R)) res+=relu(x-pos)*num; return res; } }; signed main(){ int m,n;cin>>m>>n; vector a(m),b(n); cin>>a>>b; struct E{ ll val; bool a; E(ll val,bool a):val(val),a(a){} }; vector v; rep(i,m) v.emplace_back(a[i],true); rep(i,n) v.emplace_back(b[i],false); sort(ALL(v),[](E l,E r){return l.val f; f.add_x_minus_a(0,1000000000); f.add_a_minus_x(0,1000000000); ll pre=-100000; for(int i=0;i<(int)v.size();i++){ ll nxt=(i==(int)v.size()?INF:v[i+1].val); ll d=nxt-v[i].val; bool is_a=v[i].a; if(is_a){ f.shift(-1); f.apply_cumulative_min(); f.add_x_minus_a(0,d); f.add_a_minus_x(0,d); }else{ f.shift(k); f.apply_cumulative_min(); f.add_x_minus_a(0,d); f.add_a_minus_x(0,d); } } cout<