daily pastebin goal
20%
SHARE
TWEET

Persian Party

a guest Mar 10th, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. int main(){
  7.  
  8.     long n, v=0;
  9.         cin>> n;
  10.  
  11.     vector <long> a(n);
  12.     vector <long> d(n);
  13.  
  14.         for(long i=0; i<n; i++){
  15.             cin>> a[i];
  16.             cin>> d[i];
  17.         }
  18.     sort(a.begin(), a.end());
  19.     sort(d.begin(), d.end());
  20.  
  21.     for(long p=0, i=0, j=0; i<n;){
  22.         if(a[i]<d[j]){
  23.             p++;
  24.             v+=p-1;
  25.             i++;
  26.         }
  27.         else{
  28.             p--;
  29.             j++;
  30.         }
  31.     }
  32.     cout<<(v+n)*2;
  33. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top