Guest User

Untitled

a guest
Apr 26th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.58 KB | None | 0 0
  1. /* Bismillahir Rahmanir Rahim */
  2. /*Coder: Ahmad Faiyaz*/
  3.  
  4. #include <algorithm>
  5. #include <cctype>
  6. #include <cmath>
  7. #include <cstdio>
  8. #include <cstdlib>
  9. #include <cstring>
  10. #include <iostream>
  11. #include <map>
  12. #include <queue>
  13. #include <set>
  14. #include <sstream>
  15. #include <stack>
  16. #include <string>
  17. #include <vector>
  18.  
  19. # define FOR(i, a, b) for (int i=a; i<b; i++)
  20. # define REP(i, a) FOR(i,0,a)
  21.  
  22. #define EPS 1e-11
  23. #define inf ( 1LL << 31 ) - 1
  24. #define LL long long
  25.  
  26. #define abs(x) (((x)< 0) ? (-(x)) : (x))
  27. #define all(x) (x).begin(), (x).end()
  28. #define ms(x, a) memset((x), (a), sizeof(x))
  29.  
  30. # define VI vector<int>
  31. # define VS vector<string>
  32. # define VC vector<char>
  33.  
  34. #define mp make_pair
  35. #define pb push_back
  36. #define sz(k) (int)(k).size()
  37. #define FORIT(i,m) for(__typeof((m).begin()) i=(m).begin();i!=(m).end();i++)
  38. #define vlong long long
  39. using namespace std;
  40. long long v [2005];
  41. int main(){
  42.     int t,chk=1,n;
  43.     scanf("%d",&t);
  44.     while(t--){
  45.         scanf("%d",&n);
  46.         //vector<long long int>::iterator low,up;
  47.         int low,up;
  48.         for(int i=0;i<n;i++){
  49.             scanf("%lld",&v[i]);
  50.         }
  51.         sort(v,v+n);
  52.         int count=0;
  53.         for(int i=0;i<n;i++){
  54.             for(int j=i+1;j<n;j++){
  55.               //  low=lower_bound(v,v+n,sum);
  56.                // up=upper_bound(v,v+n,v[j]);
  57.               //  int c=int(low-v.begin());
  58.                // int d=int(up-v.begin());
  59.                count+=(lower_bound(v,v+n,v[i]+v[j])-upper_bound(v,v+n,v[j]));
  60.             }
  61.         }
  62.         printf("Case %d: %d\n",chk++,count);
  63.     }
  64. }
Add Comment
Please, Sign In to add comment