#include<iostream> #include<set> #include<unordered_map> using namespace std; int main() {     int n, k;     cin >> n >> k;     int tmp;     set<int> input;     for (int i = 0; i < n; ++i) {         cin >> tmp;         input.insert(tmp);     }     unordered_map<int, int> hashmap;     int count = 0;     for (auto i = input.begin(); i != input.end(); i++)     {         if (hashmap[*i - k] == *i)             count++;         else             hashmap[*i - k] = *i;         if (hashmap[*i] == *i + k)             count++;         else             hashmap[*i] = *i + k;     }     cout << count;     return 0; }
点赞 评论

相关推荐

牛客网
牛客网在线编程
牛客网题解
牛客企业服务