daily pastebin goal
46%
SHARE
TWEET

Untitled

a guest Dec 6th, 2014 282 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.  int N, K;
  9.  cin >> N >> K;
  10.  
  11.  long long a[N];
  12.  
  13.  for(int i = 0; i < N;i++)
  14.  cin >> a[i];
  15.  
  16.  sort(a, a + N);
  17.  
  18.  long long ans = 0;
  19.  long long t;
  20.  int j;
  21.  for(int i = 0; i < N - 1; i++)
  22.  {
  23.     t = K + a[i] - 1;
  24.         j = upper_bound(a + i, a + N, t)  - a;
  25.         if((a[j] - a[i]) >= K & j <= N - 1)
  26.         ans += N - j;
  27.  }
  28.  cout << ans;
  29.  
  30.  
  31. }
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