Advertisement
a53

CountSumS

a53
Nov 1st, 2021
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.29 KB | None | 0 0
  1. long long CountSumS(vector<int> &a,int s)
  2. {
  3. int n=a.size();
  4. if(n<=1)
  5. return 0;
  6. unordered_map<int,int> M;
  7. M.clear();
  8. long long cnt=0;
  9. for (int i=0;i<n;++i)
  10. {
  11. if(M[s-a[i]]>0)
  12. cnt+=M[s-a[i]];
  13. ++M[a[i]];
  14. }
  15. return cnt;
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement