Advertisement
Mihai_Preda

Untitled

Feb 6th, 2021
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5. int main()
  6. {
  7.     int n,cnt=0;
  8.     cin >> n;
  9.     vector<int> v(n);
  10.     for(int i=0;i<n;i++)
  11.         cin >> v[i];
  12.     sort(v.begin(),v.end());
  13.     for(int i=0; i<n; i++)
  14.     {
  15.         for(int j=i+1; j<n;j++)
  16.         {
  17.             int poz = lower_bound(v.begin(), v.end(), v[i]+v[j]) - v.begin();
  18.             cnt = cnt + poz - j - 1;
  19.         }
  20.     }
  21.     cout << cnt;
  22.     return 0;
  23. }
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement