Created
March 13, 2020 17:30
-
-
Save tony9402/54a36485957667b0f5b2cce3c0886efe to your computer and use it in GitHub Desktop.
Codeforces
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 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