Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstdlib>
- #include<algorithm>
- #include<vector>
- //#include<conio.h>
- #define long long long
- #define nln '\n'
- using namespace std;
- int main()
- {
- // Input
- cin.tie(0)->sync_with_stdio(0);
- cout.tie(0)->sync_with_stdio(0);
- //freopen("doll.inp", "r", stdin);
- long n, k;
- cin >> n >> k;
- vector<long> a(n);
- for (auto &i : a)
- {
- cin >> i;
- i *= -1;
- }
- sort(a.begin(), a.end());
- // Process
- long ans = 0;
- while (!a.empty())
- {
- ans += a[0]*(-1);
- long pst = 0;
- while (pst != (long)a.size())
- {
- long cor = a[pst];
- a.erase(a.begin()+pst);
- pst = (long)(lower_bound(a.begin(), a.end(), cor+k)-a.begin());
- }
- }
- cout << ans << nln;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment