Codeforces Round 627 (Div. 3) 1324D. Pair of Topics Solution
Problem Link : https://codeforces.com/contest/1324/problem/D
Solution in C++:
- /// La ilaha illellahu muhammadur rasulullah
- ///******Bismillahir-Rahmanir-Rahim******///
- /// Abul Hasnat Tonmoy
- /// Department of CSE,23rd batch
- /// Islamic University,Bangladesh
- ///**********ALLAH IS ALMIGHTY************///
- #include <bits/stdc++.h>
- using namespace std;
- int32_t main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int n ;
- cin >> n ;
- int a[n+1],b[n+1] ;
- vector<int > c(n);
- for ( int i = 0 ; i < n ; i++ ) cin >> a[i] ;
- for ( int i = 0 ; i < n ; i++ ) cin >> b[i] ;
- for ( int i = 0 ; i < n ; i++ ) {
- c[i] = a[i] - b[i] ;
- }
- sort (c.begin() , c.end()) ;
- long long ans = 0 ;
- for ( int i = 0 ; i < n ; i++ ) {
- if (c[i] > 0){
- int pos = lower_bound(c.begin(),c.end(),-c[i]+1)-c.begin() ;
- ans += (i - pos);
- }
- else
- continue ;
- }
- cout << ans << endl;
- return 0;
- }
No comments