Skip to content

Instantly share code, notes, and snippets.

@tony9402
Created March 13, 2020 17:30
Show Gist options
  • Save tony9402/54a36485957667b0f5b2cce3c0886efe to your computer and use it in GitHub Desktop.
Save tony9402/54a36485957667b0f5b2cce3c0886efe to your computer and use it in GitHub Desktop.
Codeforces
#include<bits/stdc++.h>
#define endl "\n";
using namespace std;
typedef long long ll;
int arr[200001], inf = 1000000000;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n; cin >> n;
for (int i = 0; i < n; i++) cin >> arr[i];
for (int i = 0; i < n; i++) {
int x; cin >> x;
arr[i] -= x;
}
sort(arr, arr + n);
ll ans = 0;
for (int i = 0; i < n; i++) {
ll idx = upper_bound(arr + i + 1, arr + n, inf) - lower_bound(arr + i + 1, arr + n, -arr[i] + 1);
ans += idx;
}
cout << ans;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment