Codeforces Round 627 (Div. 3) 1324D. Pair of Topics Solution

                               


  Problem Link : https://codeforces.com/contest/1324/problem/D

Solution in C++:

  1. /// La ilaha illellahu muhammadur rasulullah
  2. ///******Bismillahir-Rahmanir-Rahim******///
  3. /// Abul Hasnat Tonmoy
  4. /// Department of CSE,23rd batch
  5. /// Islamic University,Bangladesh
  6. ///**********ALLAH IS ALMIGHTY************///
  7. #include <bits/stdc++.h>
  8. using namespace std;
  9. int32_t main() {
  10. ios_base::sync_with_stdio(0);
  11. cin.tie(0);
  12. int n ;
  13. cin >> n ;
  14. int a[n+1],b[n+1] ;
  15. vector<int > c(n);
  16. for ( int i = 0 ; i < n ; i++ ) cin >> a[i] ;
  17. for ( int i = 0 ; i < n ; i++ ) cin >> b[i] ;
  18. for ( int i = 0 ; i < n ; i++ ) {
  19. c[i] = a[i] - b[i] ;
  20. }
  21. sort (c.begin() , c.end()) ;
  22. long long ans = 0 ;
  23. for ( int i = 0 ; i < n ; i++ ) {
  24. if (c[i] > 0){
  25. int pos = lower_bound(c.begin(),c.end(),-c[i]+1)-c.begin() ;
  26. ans += (i - pos);
  27. }
  28. else
  29. continue ;
  30. }
  31. cout << ans << endl;
  32. return 0;
  33. }

No comments

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.