Untitled

mail@pastecode.io avatar
unknown
plain_text
25 days ago
912 B
0
Indexable
Never
// Ai + Aj > Bi + Bj
// Ai - Bi > Bj - Aj

// -(Bi - Ai) > (Bj - Aj)

// number of elements ci s.t. i < j & ci < -X
// => lower_bound of -x in c[0, j)


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define endl "\n"
 
const double PI = 3.14159265358979;
const ll INF =  1e9 + 7;
const ll MOD = 1e9 + 7;
const ll nax = 2505;
const int LOG = 25;


void solve() {
    int n;
    cin >> n;
    int a[n], b[n], c[n];

    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];

        c[i] = b[i] - a[i];
    }

    sort(c, c + n);
    
    ll cnt = 0;
    for (int j = 1; j < n; j++) {
        cnt += lower_bound(c, c + j, -c[j]) - c;
    }

    cout << cnt << endl;
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int t; cin >> t; while(t--)
    solve();
    return 0;
}
Leave a Comment