SHARE
TWEET

Untitled

a guest Jan 15th, 2020 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4. int n,i,v[1000],m,p,u,k,j,s;
  5. int main()
  6. {
  7.     cin>>n;
  8.     for(i=1; i<=n; i++)
  9.     {cin>>v[i];}
  10.     sort (v+1,v+n+1);
  11.     for(i=1;i<=n-2;i++)
  12.     {
  13.          for(j=i+1;j<=n-1;j++)
  14.          {
  15.              p=i+j;
  16.              u=n;
  17.              s=v[i]+v[j];
  18.              while(p<=u)
  19.              {
  20.                  m=(p+u)/2;
  21.                  if(s>v[m]) {p=m+1;}
  22.                  else {u=m-1;}}
  23.                  k=k+u-j;
  24.              }
  25.  
  26.                       }
  27.                       cout<<k;
  28.                       return 0;
  29. }
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