fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int ans(vector<int>v,int k){
  5. map<int,int>m;
  6. int a=0;
  7. for(int i=0;i<v.size();i++){
  8. a+=m[k-v[i]];
  9. m[k-v[i]]++;
  10. }
  11. return a;
  12. }
  13. int main() {
  14. // your code goes here
  15. int n;cin>>n;
  16. vector<int>v(n);
  17. for(int i=0;i<n;i++)cin>>v[i];
  18. int k;cin>>k;
  19. cout<<ans(v,k)<<endl;
  20. return 0;
  21. }
Success #stdin #stdout 0.01s 5292KB
stdin
5
1 2 3 4 5
5
stdout
0