Last active
November 27, 2016 12:02
-
-
Save Hunachi/2d8b2fd1e47b36e44a512c7ad138b61c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> | |
#define int long long int | |
#define rep(a,b,c) for(int a=b;a<c;a++) | |
#define repm(a,b,c) for(int a=(b-1);a>=c;a--) | |
#define pb push_back | |
#define str string | |
#define sf(a) scanfs("%d",&a) | |
#define pb push_back | |
#define mp make_pair | |
#define Fi first | |
#define Se second | |
#define ALL(v) (v).begin(), (v).end() | |
using namespace std; | |
const int INF = 1e18 + 9; | |
const int Mod = 1e9 + 7; | |
inline int replac(str s){double ans=0;rep(i,0,s.length()){ans+=(s[i]-'0')*pow(10,s.length()-i-1);}return (int)ans;} | |
inline string numstr(int m){str s="";while(m>0){char c;int a=m/10;if(a>0)a=m%(a*10);else a=m;c=(char)('0'+a);s+=c;m/=10;}str st="";for(int i=s.size()-1;i>=0;i--){st+=s[i];}return st;} | |
typedef vector<int> vi; | |
typedef pair<int,int> pii; | |
typedef vector<pii> vii; | |
vi a,b; | |
vector<double> f; | |
signed main() | |
{ | |
cin.tie(0); | |
ios::sync_with_stdio(false); | |
int n,m; | |
double d; | |
while(1){ | |
cin >> d; | |
if(d==0)break; | |
a.clear();b.clear();f.clear(); | |
cin >> n >> m; | |
double sa=0; | |
double x; | |
a.pb(0); | |
rep(i,0,n-1){ | |
cin >> x; | |
a.pb(x); | |
f.pb((sa+x)/2); | |
//cout << (sa+x)/2 << "sa" << endl; | |
sa=x; | |
} | |
f.pb((x+d)/2); | |
//cout <<(x+d)/2 << "sa" << endl; | |
rep(i,0,m){ | |
int x; | |
cin >> x; | |
b.pb(x); | |
} | |
sort(ALL(a)); | |
sort(ALL(b)); | |
//for(double v:f){ | |
// cout << v << "v" << endl ; | |
//} | |
int ans=0,cou=0; | |
bool ok=false; | |
rep(i,0,m){ | |
//if(f[cou]<b[i]){ | |
if(f[0]>b[i]){ | |
ans+=b[i]; | |
}else if(f[n-1]<=b[i]){ | |
ans+=(d-b[i]); | |
}else { | |
rep(j,cou,n){ | |
if(f[j]>=b[i]){ | |
//cout << cou << " cou " << j << endl; | |
cou=j; | |
ans+=abs(a[cou]-b[i]); | |
break; | |
} | |
} | |
} | |
//cout << ans << " " << cou << endl; | |
} | |
cout << ans << endl; | |
} | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment