Advertisement
Guest User

Untitled

a guest
Dec 4th, 2014
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.36 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6. long long n, k, a[100005];
  7. int main()
  8. {
  9.     cin >> n >> k;
  10.     for(int i = 0; i < n; i++) cin >> a[i];
  11.  
  12.     sort(a, a + n);
  13.  
  14.     long long cnt = 0;
  15.  
  16.     for(int i = 0; i < n; i++)
  17.     {
  18.         int t = lower_bound(a, a + n, k - a[i]) - a - 1;
  19.         if(t < i) break;
  20.         else cnt += t - i;
  21.     }
  22.  
  23.     cout << cnt;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement