Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
3.9 kB
3
Indexable
Never
/*
   _________________________
   | Written by vanshdhawan60 |
     ---------~u~---------  
*/

#include <bits/stdc++.h>
using namespace std;

/*_____________________________ MACRO DEFINITIONS ____________________________*/
#define endl "\n"
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define int long long  // alert!
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using pii = pair<int, int>;
using vvi = vector<vi>;
using vpii = vector<pii>;

//some useful functions and identifiers as macro
#define ff first
#define ss second
#define pb push_back
#define set_bits __builtin_popcountll
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define MOD 1000000007
#define PI 3.141592653589793238462
#define rep(i, a, b) for(int i = (a); i < (b); i++)
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());

/*______________________ COMMON FUNCTION DEFINITIONS _________________________*/

int mpow(int base, int exp) { //binary exponentiation (modular power) (change MOD if required)
  base %= MOD;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % MOD;
    base = ((ll)base * base) % MOD;
    exp >>= 1;
  }
  return result;
}

int mdivide (int a, int b) {  //valid when MOD is prime
  return ((ll) (a%MOD) * mpow(b,MOD-2)) % MOD;
}

/*_________________________________ DEBUGGER ________________________________*/

#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif

void _print(ll t) {cerr << t;}
//void _print(int t) {cerr << t;}   // !enable when using int & ll separately
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(ld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}

template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
/////  debug code end




/*___________________________WRITE CORE LOGIC HERE_____________________*/





void solve () {
    int n; cin>>n;
    vi a(n), b(n);
    rep(i,0,n) cin>>a[i];
    rep(i,0,n) cin>>b[i];
    vpii temp(n);
    rep(i,0,n) temp[i] = {a[i] + b[i], i};
    sort(temp.rbegin(), temp.rend());

    int ans=0, turn=1;
    for (auto [s, idx]: temp) {
        if (turn&1) {
            ans += a[idx]-1;
        }
        else ans -= (b[idx]-1);
        turn ^= 1;
    }
    cout << ans << "\n";
}





/*___________________________END OF CORE CODE, GoodLuck_____________________*/

signed main()
{
    fastio();
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

    int t=1;
    cin>>t;
    auto t1 = std::chrono::high_resolution_clock::now();
    while(t--)
    {
        solve ();
    }
    auto t2 = std::chrono::high_resolution_clock::now();


    #ifndef ONLINE_JUDGE
    std::chrono::duration<double, std::milli> ms_double = t2 - t1;
    cout << "\n\n" << ms_double.count() << "ms\n";
    #endif

}

/*
   _________________________
   | Written by vanshdhawan60 |
     ---------~u~---------  
*/
Leave a Comment