Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ll long long
- #define ull unsigned long long
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- ll n;
- cin >> n;
- vector<ll>a(n);
- vector<ll>b(n);
- for (auto &i:a) cin >> i;
- for (auto &i:b) cin >> i;
- map<ll,ll>m;
- for (int i=0; i<n; i++) {
- m[a[i]-b[i]]++;
- }
- auto x=--m.rbegin();
- while (x!=m.rend()) {
- auto y= --x;
- x++;
- x->second += (y)->second;
- x++;
- }
- ll ans=0;
- for (int i=0; i<n; i++) {
- auto z=m.upper_bound(b[i]-a[i]);
- if (z!=m.end()) {
- ans+=z->second;
- if (b[i]<a[i]) ans--;
- }
- }
- cout << ans/2 << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment