fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. const int Mod=1e9+7;
  5. const ll INF = 10000000000000;
  6. const int N = 1e6+7;
  7.  
  8. void solve() {
  9. int n;
  10. cin >> n;
  11. vector<pair<int,int>> a(n);
  12. for(int i=0;i<n;i++) cin >> a[i].first;
  13. for(int i=0;i<n;i++) cin >> a[i].second;
  14. vector<int> ch(n);
  15. for(int i=0;i<n;i++) ch[i]=a[i].first-a[i].second;
  16. sort(ch.begin(),ch.end());
  17. int l=0,r=n-1;
  18. int ans = 0;
  19. while(l<=r){
  20. if(ch[l]+ch[r]>0){
  21. ans+=r-l;
  22. r--;
  23. }
  24. else l++;
  25. }
  26. cout << ans << '\n';
  27. }
  28.  
  29. int main(){
  30. ios::sync_with_stdio(false);
  31. cin.tie(nullptr);
  32.  
  33. /*int t;
  34.   cin >> t;
  35.   while (t--)*/ solve();
  36.  
  37. return 0;
  38. }
  39.  
Success #stdin #stdout 0.01s 5288KB
stdin
4
1 3 2 4
1 3 2 4
stdout
0