lina_os

Untitled

Apr 26th, 2025
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define ull unsigned long long
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  9.     ll n;
  10.     cin >> n;
  11.     vector<ll>a(n);
  12.     vector<ll>b(n);
  13.     for (auto &i:a) cin >> i;
  14.     for (auto &i:b) cin >> i;
  15.     map<ll,ll>m;
  16.     for (int i=0; i<n; i++) {
  17.         m[a[i]-b[i]]++;
  18.     }
  19.     auto x=--m.rbegin();
  20.     while (x!=m.rend()) {
  21.         auto y= --x;
  22.         x++;
  23.         x->second += (y)->second;
  24.         x++;
  25.     }
  26.     ll ans=0;
  27.     for (int i=0; i<n; i++) {
  28.         auto z=m.upper_bound(b[i]-a[i]);
  29.         if (z!=m.end()) {
  30.             ans+=z->second;
  31.             if (b[i]<a[i]) ans--;
  32.         }
  33.     }
  34.     cout << ans/2 << endl;
  35.     return 0;
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment