Codeforces 1038 C. Gambling
阿新 • • 發佈:2018-12-11
#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <ctime> #include <iostream> #include <algorithm> #include <string> #include <vector> #include <deque> #include <list> #include <set> #include <map> #include <stack> #include <queue> #include <numeric> #include <iomanip> #include <bitset> #include <sstream> #include <fstream> #define debug puts("-----") #define pi (acos(-1.0)) #define eps (1e-8) #define inf (1<<30) using namespace std; typedef long long ll; int n; int a[100100], b[100100]; int main(int argc, char const *argv[]) { cin>>n; for(int i = 1; i <= n ; ++i) { cin>>a[i]; } for(int i = 1; i <= n ; ++i) { cin>>b[i]; } sort(a+1, a+n+1); sort(b+1, b+n+1); ll t=0; ll x=n,y=n; ll ans_a=0, ans_b=0; while(x>0||y>0) { if(!(t&1)) { if(a[x]>b[y]) ans_a+=a[x], x--; else y--; // cout<<"a"<<" "<<ans_a<<endl; } else { if(b[y]>a[x]) ans_b+=b[y], y--; else x--; // cout<<"b"<<" "<<ans_b<<endl; } t++; } ll ans = ans_a-ans_b; cout<<ans<<endl; return 0; }