daily pastebin goal
37%
SHARE
TWEET

Untitled

a guest Dec 6th, 2014 192 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. sort(a, a + n);
  2. int ans = 0, j = 0;
  3. for(int i = 0; i < n; i++)
  4. {
  5.         while(a[j] - a[i] < k) j++;
  6.         if(j >= n) break;
  7.         ans += n - j;
  8. }
  9. cout << ans;
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