Advertisement
erfanul007

LOJ 1307

Dec 1st, 2018
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int t,i;
  6. scanf("%d",&t);
  7. for(i=1;i<=t;i++){
  8. int n,x,j,k;
  9. long long int cnt;
  10. scanf("%d",&n);
  11. vector<int>vt;
  12. for(j=0;j<n;j++){
  13. scanf("%d",&x);
  14. vt.push_back(x);
  15. }
  16. cnt=0;
  17. sort(vt.begin(),vt.end());
  18. for(j=0;j<n-2;j++){
  19. for(k=j+1;k<n-1;k++){
  20. int l=upper_bound(vt.begin(),vt.end(),vt[j]+vt[k]-1)-vt.begin()-1;
  21. cnt=cnt+l-k;
  22. }
  23. }
  24. printf("Case %d: %lld\n",i,cnt);
  25. vt.clear();
  26. }
  27. return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement