Advertisement
Falak_Ahmed_Shakib

lower_bound

Apr 14th, 2020
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. // In the name of Allah.
  2. // We're nothing and you're everything.
  3. // Ya Ali!
  4. /*
  5. , \ / ,
  6. / \ )\__/( / \
  7. / \ (_\ /_) / \
  8. ____/_____\__\@ @/___/_____\____
  9. | |\../| |
  10. | \VV/ |
  11. | ------___------- |
  12. |__________Chuta Dragon___________|
  13. | /\ / \\ \ /\ |
  14. | / V )) V \ |
  15. |/ ` // ' \|
  16. ` V '
  17. */
  18.  
  19. #include<bits/stdc++.h>
  20. using namespace std;
  21. typedef long long ll;
  22. #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL))
  23. #define fi first
  24. #define se second
  25. #define pb push_back
  26. ll const MOD=1000000007;
  27. ///-------------------------------------------------------------------------------------------------///
  28. /// KARMA IS LIKE 69,,, YOU GET WHAT YOU GIVE ///
  29. ///-------------------------------------------------------------------------------------------------///
  30.  
  31.  
  32.  
  33. #define eb emplace_back
  34.  
  35.  
  36.  
  37. int main()
  38. {
  39. fastread();
  40.  
  41. ll n,k;
  42.  
  43. cin>>n>>k;
  44.  
  45. ll cnt=0,ara[n+1];
  46.  
  47. for(ll i=0;i<n;i++)
  48. {
  49.  
  50. cin>>ara[i];
  51.  
  52. // if(a<k)cnt++;
  53.  
  54. }
  55.  
  56. sort(ara,ara+n);
  57.  
  58. ll sum=0;
  59.  
  60. for(ll i=0;i<n;i++)
  61. {
  62. ll a;
  63.  
  64. a=k-ara[i];
  65. //cout<<a<<endl;
  66.  
  67. if(a>0) {
  68. ll pos=lower_bound(ara,ara+n,a)-ara;
  69. // cout<<pos<<" pos"<<endl;
  70. cnt=pos-i-1;
  71. if(cnt>0)sum+=cnt;
  72. // cout<<cnt<<endl;
  73. // break;
  74.  
  75.  
  76. }
  77.  
  78.  
  79. }
  80.  
  81. // cout<<cnt<<endl;
  82.  
  83. // cout<<(cnt*(cnt+1))/2<<endl;
  84.  
  85.  
  86. cout<<sum<<endl;
  87.  
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement