using System; using System.Collections.Generic; using System.Collections; using System.Collections.Specialized; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.IO; using System.Reflection; using static System.Math; using System.Numerics; using System.Threading; using System.Runtime.CompilerServices; using System.Diagnostics; //using nint=System.Int32; static class Program{ const long inf=long.MaxValue>>1; const int mod=(int)1e9+7;//998244353; static void Main(){ Sc sc=new Sc(); var (n,m)=sc.Tp2(); var a=sc.Ia3(mod<<1); var b=sc.Ia2; b[0]=-mod; var dp=new long[m+1][]; dp[0]=new long[]{0,inf}; for(int i = 1,l=0,r=0;i<=m;i++) { dp[i]=new long[]{inf,inf}; var br=false; var bl=false; while(a[r]a[l]){dp[i][0]=dp[i-1][0]+b[i]-b[i-1];} if(b[i]>a[l]){dp[i][0]=Min(dp[i][0],Min(dp[i-1][0],dp[i-1][1])+b[i]-a[l]);} if(!br&&b[i](int n,Func f){var a=new T[n];for(int i=0;i(int n,Func f){var a=new T[n];for(int i=0;i(int n,Func f){var a=new T[n];for(int i=0;i(int n,Func f){var a=new T[n];for(int i=0;i(){var s=Console.ReadLine().Split();return (Ct(s[0]),Ct(s[1]));} public (T,T,T) Tp3(){var s=Console.ReadLine().Split();return (Ct(s[0]),Ct(s[1]),Ct(s[2]));} public (T,T,T,T) Tp4(){var s=Console.ReadLine().Split();return (Ct(s[0]),Ct(s[1]),Ct(s[2]),Ct(s[3]));} public (T,T,T,T,T) Tp5(){var s=Console.ReadLine().Split();return (Ct(s[0]),Ct(s[1]),Ct(s[2]),Ct(s[3]),Ct(s[4]));} public (T1,T2) Tp2(){var s=Console.ReadLine().Split();return (Ct(s[0]),Ct(s[1]));} public (T1,T1,T2) Tp3(){var s=Console.ReadLine().Split();return (Ct(s[0]),Ct(s[1]),Ct(s[2]));} private T Ct(string s){return (T)Convert.ChangeType(s,typeof(T));} }