Advertisement
Guest User

Untitled

a guest
Jan 15th, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement