We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
#include <map>#include <set>#include <list>#include <cmath>#include <ctime>#include <deque>#include <queue>#include <stack>#include <bitset>#include <cstdio>#include <limits>#include <vector>#include <cstdlib>#include <numeric>#include <sstream>#include <iostream>#include <algorithm>usingnamespacestd;/* Head ends here */intpairs(vector<longlongint>a,longlongintn,longlongintk,longlongintmax){longlongintans=0;longlongintc[max]={0};for(inti=0;i<n;i++){c[a[i]]=1;}for(inti=0;i<n;i++){if(c[a[i]+k]==1)ans++;}returnans;}/* Tail starts here */intmain(){longlongintres;longlongint_a_size,_k;cin>>_a_size>>_k;cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n');vector<longlongint>_a;longlongint_a_item;for(longlongint_a_i=0;_a_i<_a_size;_a_i++){cin>>_a_item;_a.push_back(_a_item);}longlongintmax=-1;for(autoval:_a){if(max<val)max=val;}res=pairs(_a,_a_size,_k,max);cout<<res;return0;}
I am quite naive, trying to implement hashing, but since the values in the array are quite big, i am getting segmentation fault, and only four test cases are cleared, please help me.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Pairs
You are viewing a single comment's thread. Return to all comments →
I am quite naive, trying to implement hashing, but since the values in the array are quite big, i am getting segmentation fault, and only four test cases are cleared, please help me.